Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Weak listeners (retitled)



Bjorn Roche wrote:

>Sorry for the confusion. I have my own objects with their own listeners. I
>use weak references to keep track of lists listeners, reducing the need to
>unregister the listeners. It has nothing to do with the
>AWTEventMulticaster and is tangential to this discussion -- I just thought
>I would comment that this strategy could be used to reduce the need to
>unregister listeners.

There are tradeoffs.

For example, if you register a listener but don't retain any other
references to it, nothing but a weak reference to the listener could GC the
listener.  Now maybe you want that, but maybe you don't.

For example, your earlier example of a nonce ActionListener (inner class)
'al' would have no other references to al other than what the JButton b is
holding.  So assuming that b is still alive and even on-screen and active,
then its listeners should still be alive and reachable.  But if JButtons
held ActionListeners only by weak references, then al or any other
listeners could go away, even though you really still want them listening
for events.  To me, that sounds like a bug, not a feature.

  -- 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



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.