This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Listeners and GC

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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 VI Editor Ubuntu
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!