Why does exist WeakHashMap, but absent WeakSet?

后端 未结 3 1510
名媛妹妹
名媛妹妹 2020-12-04 15:29

From J. Bloch

A ... source of memory leaks is listeners ... The best way to ensure that callbacks are garbage collected promptly is to store o

3条回答
  •  借酒劲吻你
    2020-12-04 15:43

    Set weakHashSet = Collections.newSetFromMap(
            new WeakHashMap());
    
    
    

    As seen in Collections.newSetFromMap documentation, passing a WeakHashMap to get a Set.

    提交回复
    热议问题