[英]Java Map Contents Upon Garbage Collection Recursive?
I use a structure like the following: 我使用如下结构:
HashMap < EnumA , HashMap < Integer , LinkedList < EnumB > > > OverallMap
If I were to do this: 如果我要这样做:
OverallMap . clear ( )
Will everything that was discarded by the clear()
(the HashMap objects, the Integer objects, and the LinkedList objects) eventually get garbage-collected, or do I have to iterate all the way down to the lists and call clear() on them before clear()
ing the inner maps and then clear()
ing the outer map? 是否最终将由
clear()
(HashMap对象,Integer对象和LinkedList对象)丢弃的所有东西都进行垃圾回收,或者我是否必须一路迭代到列表并对其调用clear()在clear()
获得内部地图之前,然后clear()
获得外部地图之前?
只要没有其他引用其他对象,它们就会被垃圾回收。
您需要做的就是在顶层调用clear()
,除非在其他地方引用了这些集合,但是您只能在一个地方将其清除。
是的,如果您使用.clear(),则除了某些TotalMap内部结构外,所有内容都将被垃圾收集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.