> I haven't done too much Swing programming in a while and I didnt
> normally throw away panels within Frames, so was wondering
[quoted text clipped - 4 lines]
> do I have to remove listeners before removing the panel
> in order to free all memory do I
No, those listeners are references from the mess of
stuff you are disconnecting to the outside - a gui
element refers to its listeners. For some versions of
Java, there are bugs that will cause gui elements not
to be garbage collected, but this has only happened
with menu elements and JInternalFrames, as far as I
know. 1.5.0 beta had such a bug for menu items, for
example.
To be sure the panel is collected, override finalize()
in the panel class so that it prints a message, like
"panel collected", and call System.gc() after removing
it. That is not guaranteed to work, of course, but in
general it will.
A heap analysis tool makes tracing references simple.
jmp is a fairly good free one. I found that most of them,
even the commercial ones, crash frequently when
applied to our project, but I was able to get jmp to work
to the point I needed it with an average of only two or
three attempts.