WeakHashMap iteration and garbage collection

前端 未结 4 1581
难免孤独
难免孤独 2020-12-10 03:30

I am using a WeaekHashMap to implement a Cache. I am wondering if I am iterating over the keys of this map, and at the same time garbage collector is actively r

4条回答
  •  醉梦人生
    2020-12-10 03:42

    The WeakHashMap is weak on the keys not the values so it is not appropriate for a cache of values if you want to release space when the value is not being used. You might want to take a look at MapMaker from the google collections.

提交回复
热议问题