Bjorn Roche wrote:
>Now, I know full well that I can increase the java stack size (I have
>managed to make them more common by reducing the size), but considering that
>most of the stack trace lies in AWTEventMulticaster and never even hits my
>code, I am concerned that this is a bug in AWT or apple's code. From
>looking at
>the AWTEventMulticaster javadocs, it appears that AWTEventMulticaster uses a
>binary-tree type structure to multicast events. Is that right? If so, am I
>doing something wrong in my code to cause so much multicasting? Do I need to
>start unregistering event listeners from deleted objects or something?
>
>Maybe someone else has experience with something simmilar? Is there a
>simple tip, like running the garbage collector more often (I've tried that)?
Running the GC'er more often won't solve anything.
If you have unused objects that are still registered as listeners, then the
unused objects aren't garbage, because they're still reachable as live
listeners. The objects could well be unreachable to the rest of your
program, but unless they're also removed as listeners, they aren't
unreachable from the GCer's viewpoint.
I suggest unregistering listeners when you no longer need them.
As a diagnostic aid, it might be more useful to REDUCE the stack-size, thus
causing failures SOONER, making them easier to track down. With some luck,
this might lead you more quickly to those places where listeners aren't
being unregistered. You have to find these large herds of listeners and
reduce their number, otherwise you're not solving the problem.
"Multicasting" for AWTEventMulticaster just means it can forward every kind
of event to every kind of listener. That is, it's usable for all event and
listener types. It doesn't mean multicasting in the internet sense.
What AWTEventMulticaster is doing is forwarding events to listeners, who
may in turn be AWTEventMulticasters forwarding events, etc. Hence the deep
stack. Regardless of the actual structure (tree, list, whatever), if you
have a large enough number of listeners, it can overflow the stack. The
only remedy I know of is "Don't do that".
AWTEventMulticaster represents a binary tree, but it isn't a balanced tree,
nor a self-balancing tree. So the order of adding and removing listeners
can lead to a representation approximating a singly-linked list (chain).
If you never remove a listener, things will go bad pretty directly. See
any of the add*Listener() methods, and AWTEventMulticaster.addInternal(),
in Sun's source.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden