Hi,
Is there any way to have the garbage collector remove not only the referent contained by a WeakReference (if the w.r. contains the only reference to the referent), but the WeakReference object itself?
I need to use a "WeakSet", and I've attempted to simulate one by loading a HashSet with WeakReferences to objects. This works fine, except it starts to fill up with empty WeakReference objects!! (once their referents have been garbage-collected).
I suppose I could use a WeakHashMap, but I don't like the idea of never using the value portion of the map. It seems strange to me that the garbage collector doesn't also remove W.R.'s, and that there appears to be no implementation of a "WeakSet" outside of a value-free WeakHashmap. That's what I'll wind up using if nothing better exists, but I would think something should..? perhaps?
thank you..!
dora
Is there any way to have the garbage collector remove not only the referent contained by a WeakReference (if the w.r. contains the only reference to the referent), but the WeakReference object itself?
I need to use a "WeakSet", and I've attempted to simulate one by loading a HashSet with WeakReferences to objects. This works fine, except it starts to fill up with empty WeakReference objects!! (once their referents have been garbage-collected).
I suppose I could use a WeakHashMap, but I don't like the idea of never using the value portion of the map. It seems strange to me that the garbage collector doesn't also remove W.R.'s, and that there appears to be no implementation of a "WeakSet" outside of a value-free WeakHashmap. That's what I'll wind up using if nothing better exists, but I would think something should..? perhaps?
thank you..!
dora