开发者

Java collection GC

开发者 https://www.devze.com 2023-04-03 08:17 出处:网络
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?

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

精彩评论

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