Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Off Topic: Java developers please read

Author: Alessandro Damiani

Date: 11:00:54 11/10/05

Go up one level in this thread



>>>The main reason of memory leaks in Java are listeners. If an object is not used
>>>through direct referencing but you have listeners on it then the garbage
>>>collector can only collect the whole set of coupled objects. For instance, if
>>>your application class references an object that never dies and this one listens
>>>to an object, then this one can never be collected. There are tools around that
>>>display currently existing objects in memory, or write your own one through Java
>>>Reflections as we did at work.
>>
>>Thanks, but we don't make extensive use of listeners.
>>I do appreciate the tip though..
>
>Ok, we don't make extensive use of WindowLIsteners or Frame Listeners,
>though we do have a few.  But... I guess your comment would include
>ActionListeners?  Most of my ActionListeners are inlined (anonymous).

Yes, any kind of listeners are candidates, also own-made listeners.

>Would they not be killed when the internal frame containing the component
>they are listening to is disposed of?

Here is an example taken from
http://forum.java.sun.com/thread.jspa?threadID=456545&messageID=2086951:
"For example, you have a window A with a button on it. Through some mechanism,
the user can open a new instance of another window B. B adds itself as a
listener to the button on A. The developer has set the defaultCloseOperation of
B to DISPOSE_ON_CLOSE. When the window is closed, it disapears and there is no
way to get it back. However, the button on A still has a reference to the B
instance as a listener. As long as A is around, no instance of B will ever be
GC'd. If the user keeps opening and closing B windows, you will have an apparent
'leak' of memory."

Interesting is this about inner classes:
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=446934

Alessandro



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.