How come JFrame instances are always reachable within a Swing application? Won't that prevent it from being garbage collected?
JFrame frame = new JFrame();
System.out.println(Window.getWindows().length); // says '1'
Calling dispose()
doesn't help. It is not even shown.
There is no getWindows method on java.awt.Windows, but there is a Frame.getFrames() method.
But I know that both of them use WeakReference to manage such things.
Basically the idea is that both Window and Frame class has a field called weakThis which is a weakreference to the current frame/window object. Whenever the object needs to be stored(for e.g. in appcontext), the weakThis field is used instead of this. (Weakreferences don't stop gc-ing of objects, in case you didn't knew)
EDIT: Window.getWindows is added in 1.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With