[Java-gnome-hackers] Handling Events in java-gnome
Brought to you by:
afcowie
From: Philip A. C. <pc...@td...> - 2002-08-09 18:47:45
|
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.=20 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=20 http://www.javaworld.com/javatips/jw-javatip79_p.html Thanks, --=20 Philip A. Chapman |