Posted by
Joachim Wesner on
URL: http://imagej.273.s1.nabble.com/When-to-remove-listeners-or-not-tp3691065.html
Hi,
when extending one of my recent plugins (the idea was that I have a plugin
that creates two image windows from an "extended" ImageProcessor and I
added a dialog to automatically close the "child window" when the parent
was closed, I noticed sometjhing unsual that I at first did not understand.
Now I seem to understand, but I´m now insecure if I am writing unsave code
recently.
Question: Do I regularly need to remove any (ImageJ) listeners I use? The
problem is, sometimes it is difficult to tell when exactly the object get´s
out of focus and I thought that the listener will automatically
removed when the object that uses it is GCed. (As I learned, you normally
should not use finalize in Java) Up till now, I have seen no problems with
not explicitely removing listeners (as for ex. dialog listeners or mouse
listeners)
One special case however seem to be ImagePluses (or similar...?) Clearly
ImagePluses survive even if the plugin etc. that created them has removed
all references to those (So ImageJ keeps a reference somewhere, otherwise
all windows might disappear again as soon as a plugin that created them has
finished running) However, what I discovered is, that this reference is
also not removed when a window is closed (The respectively ImageListener
was still active as I could prove) Is this intended?
In the current situation it seems that removing an ImageListener is
somewhat tricky, somehow you need the ImageListener itself to detect the
closing event that can finally remove it....... :-))
(I have also seen examples that track WindowEvent.WINDOW_CLOSING to achieve
this)
What is the correct way? Any general suggestions on Listener removal?
Thanx
Joachim
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit
http://www.messagelabs.com/email
______________________________________________________________________