From J. Bloch
A ... source of memory leaks is listeners ... The best way to ensure that callbacks are garbage collected promptly is to store only weak references to them, for instance, by storing them only as keys in a WeakHashMap.
So, why there isn't any WeakSet in the Java Collections framework?
WeakHashMap
does never “ensure that callbacks are garbage collected promptly”, but rather makes them horribly non-deterministic. The garbage collector will only run when there is insufficient memory, hence, such weak listeners may be dangling around an arbitrary long time and still getting executed, but even worse, such listeners might spuriously disappear when you still need them, as it now needs an actually unrelated strong reference to keep them alive. – Waiver