When will Java WeakHashMap clean null key?

后端 未结 4 953
悲哀的现实
悲哀的现实 2021-01-14 06:05

In the code below nameRef.get() is null , after name = null and System.gc().

import java.lang.ref.WeakReference;

publ         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-14 06:47

    Your demo has some problems. In fact, the size is 0 after System.gc(). In you situation is because when print the map's size GC has not finished yet, so the result is 1

提交回复
热议问题