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 ]
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.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
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.