| Author |
Listeners and GC
|
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
When adding listeners to components (e.g. addActionListener), do we need to remove them explicitly afterwards, or will the garbage collector clear them properly when a window is closed ? I'm using a profiler and it seems that the listener stays around unless I explicitly remove it from its source. If anybody could share some light on this. [ March 29, 2007: Message edited by: Satou kurinosuke ]
|
[My Blog]
All roads lead to JavaRanch
|
 |
Nathan Pruett
Bartender
Joined: Oct 18, 2000
Posts: 4121
|
|
You shouldn't have to remove them explicitly - they should be GCed when the component(s) they are connected to are GCed. Of course, a window "closing" may not GC any components, depending on what kind of "close" it is. Just calling setVisible(false) or dispose() doesn't GC a frame - just like any other object reference, the frame reference must be nulled, go out scope, etc. to be GCed.
|
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
Thank you. But looking at the heap, listeners really seem to be floating around if I don't remove them. I manage opened frames in a collection. I'll check that references are nulled out properly on closing.
|
 |
 |
|
|
subject: Listeners and GC
|
|
|