• Post Reply Bookmark Topic Watch Topic
  • New Topic

Listeners and GC  RSS feed

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!