posted 6 years ago
A WeakHashMap holds weak references to the keys. That means that when the rest of your application (outside the map) no longer has references to objects that are used as keys in your map, then the map won't prevent the keys from being garbage collected.
"Why would you want to have a Map that can randomly lose entries?", one might ask. WeakHashMap is great for maintaining extra information about objects, as long as those objects are still around.