Cannot understand reachability

Questions about YourKit Java Profiler
Post Reply
jun
Posts: 11
Joined: Fri Feb 07, 2020 7:02 am

Cannot understand reachability

Post by jun »

Hi,
To understand more, I am reading https://www.yourkit.com/docs/java/help/reachability.jsp, but cannot understand yet.
For example,
Strong reachable: objects reachable from GC roots via at least one strong reference, or being GC roots themselves. Such objects will not be garbage collected until all strong references to them are nulled and/or they remain GC roots. Thus, memory leaks should be searched among them.
Why memory leaks should be searched among strong reachable objects? It could be reachable from GC roots because GC has information for those, so they are not garbage collected because they are used also. So, I reckoned If they are nulled, then GC could garbage collected.
What's wrong in my thought?
Thanks.
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Cannot understand reachability

Post by Anton Katilin »

Hi,

I'm afraid I don't understand your question.

What do you find unclear in particular?

> Why memory leaks should be searched among strong reachable objects?

Memory leaks may exist among strong reachable objects only, because objects of all other reachability scopes will eventually be collected, unless a strong reference to them is created before they become fully unreachable.

> It could be reachable from GC roots because GC has information for those, so they are not garbage collected because they are used also.

Exactly. The objects reachable from GC roots _are_ strongly reachable. The definition you cited tells exactly that. Where do you see a controversy?

Best regards,
Anton
Post Reply