开发者

Java collection GC

If I created inside method some kind of collection - list, array or map, after exiting from method if this collection contains references also for externa开发者_如何学运维l objects GC free the memory? Or it will be memory leak? Thanks.


No, there will be no leak. Once your code has no references to a given object, the object becomes eligible for garbage collection.

It does not matter whether the object itself (e.g. a collection) contains references to live objects -- it's references in the opposite direction that matter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜