Shesh, All that typing, and I didn't attach the file....
I haven't compiled or run this code. I hacked it from another project
I'm working on where I use weak references for listeners. I just wanted
to give you something to look at.
On Fri, 2002-08-09 at 13:49, Philip A. Chapman wrote:
> Everyone,
>
> As we are working on the new API for java-gnome, we should think about
> how events will be treated. Should we use the event/listener model used
> by swing and so familiar to most Java developers? The obvious reason to
> use it is simply because it is so familiar to Java developers. The
> down-side is that (a) it can be slow if you have a lot of listeners or a
> lot of different levels though which events must pass and (b) developers
> do not always unregister listeners when its usefullness has expired;
> causing memory leaks.
>
> The problem with memory leaks can be solved for the most part using weak
> references. I'm attaching an example from one of my other projects.
> Because this example runs in a thread and WeakHashMap is not
> syncronized, garbage collected listeners' WeakReferences are not
> removed. This is not a perfect example. I'm trading a small memory
> leak for a potential larger one. There are other methods. We could
> wrap the WeakHashMap and make is serializable. We could use also do
> some things with the ReferenceQueue as well.
>
> Anyway, just a few thoughts. A good reference is
>
> http://www.javaworld.com/javatips/jw-javatip79_p.html
>
>
> Thanks,
> --
> Philip A. Chapman
--
Philip A. Chapman
|