[java-gnome-hackers] WeakReferences going away
Brought to you by:
afcowie
From: Tom B. <Tom...@Su...> - 2003-02-27 16:38:34
|
It appears that org.gnu.gtk is misusing the WeakReference class to store its event listeners. On my system, widgets that are initially responsive to events quickly stop being responsive, even with simple Java-GNOME example apps. The problem is that the app's event listeners are being GC'd even though the widgets they are listening to are still live. A WeakReference is supposed to be used for cases where it's okay for a reference to go away, usually because it can be recreated. The classic example is with a cache; if a lookup is expensive, you cache the result in a hashtable using a WeakReference (or just use WeakHashMap) -- if the cache gets emptied by the garbage collector, it just means more lookups. The cache may have an entry disappear, but the caller never knows this because the cache is a hidden implementation detail. Event listeners need to remain permanently attached to their respective widgets, however; they are not transitory in any way. When I remove all of the WeakReference use in GTK, the problem goes away as it should. It also simplies the event handling code quite a bit, and most likely speeds it up as well. I suspect there's a lot more potential for shared code now, too. Unless anyone objects soon, I want to check in this "WeakReference-free" delta. Tom |