Forums Register Login

WeakHashMap

+Pie Number of slices to send: Send
Can anyone explain when WeakHashMap is used and how it works?? I'm studying it here but I didn't understand what's used for...
Thanks
+Pie Number of slices to send: Send
Items in a WeakHashMap are eligible for garbage collection if the WeakHashMap has the only reference.
+Pie Number of slices to send: Send
I wrote this some time ago:
+Pie Number of slices to send: Send
I think items (keys and values) in a WeakHashMap are removed from the map when the key is no longer referenced outside the map. The value then eligible for garbage collection only if it is not referenced elsewhere (perhaps by another key in the map).
I've not had an occasion in which I knew needed WeakHashMap yet, so there is a chance I don't have this right.
I suspect WeakHashMap may be useful when a subsystem needs to provide a handle by which other subsystems can refer to an object. The handle could be key in a WeakHashMap. When no other subsystem (and nothing besides the WeakHashMap) contains a reference to a particular key, that key and its value are removed from the map. At that point, if nothing else refers to the value object, the value object is unreferenced and hence eligable for garbage collection.
+Pie Number of slices to send: Send
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 663 times.
Similar Threads
GC, strange question!
WeakHashmap in java
What is a WeakHashMap?
java.util package
WeakHashMap error?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:22:47.