swing JNI how to free memory

J

John_Woo

Hi,

I had a class Screen extends JWindow, and this class had a few
attributes as

ImageIcon icon = new ImageIcon("big jpg");

JLabel lable.setIcon(icon);

then in main class, after creating Screen s, did the following:

System.gc();

Runtime r = Runtime.getruntime();

long before = r.freeMemory();

s.icon = null;
s.lable = null;
s.dispose();
s = null;
System.gc();

long after = r.freeMemory();

from (after-before), I saw free memory increased a lots, but from some
trace tool, I saw that the reference still there, like

Paths from "GC Roots" to "Object ToolkitImage #004fdf56"
sun.awt.image.ToolkitImage
image of javax.swing.ImageIcon
defaultIcon of javax.swing.JLabel
[0] of java.awt.Component[3]
component of javax.swing.JPanel
contentPane of javax.swing.JRootPane
rootPane of Screen [JNI Global]

consulting the tool vendor, it said the object is referenced by native
called, can't really free up by setting null

I'm wondering, how to clean up such object or free swing component?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top