If I created inside method some kind of collection – list, array or map, after exiting from method if this collection contains references also for external objects GC free the memory?
Or it will be memory leak?
Thanks.
If I created inside method some kind of collection – list, array or map,
Share
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.