user2282497
user2282497

Reputation: 191

Memory Leaks in Java (Swing)

My custom JPanel is retaining a large number of int arrays, as seen below in YourKit:


(source: gyazo.com)

I assumed this was the result of Graphic objects being undisposed of, but even with disposing every graphics object I use, the memory issues still occur.

The garbage collector will remove the objects if I force a heap dump (and the arrays are marked as unreachable). The behaviour causes Java to reach a high memory allocation (~700MB) however.

Are there any other common sources of this sort of issue in swing/JPanels?

Upvotes: 0

Views: 600

Answers (1)

trashgod
trashgod

Reputation: 205885

Instead of a custom JPanel, consider using JTable, which uses the flyweight pattern to render only visible cells. Moreover, a suitable TableModel may allow you to minimize the memory required for data storage. Finally, JTable supports sorting and filtering in a way that may make large datasets more manageable by the user.

Upvotes: 3

Related Questions