Let's say there are following four objects in a Java program:
- main
- a
- b
- c
The dependencies are as follows:
main ==> a ==> b ==> c
In other words, main uses a, a uses b, b uses c.
Now, value of object a changes from reference to b to null. What it means is that there are no active references to b, making it available for garbage collection:
main ==> a =/=> b ==> c
What could happen now:
A) In laymans terms, b can be garbage collected at any time. My assumption is that c will become elligible for gargabe collection only after b is garbage collected.
B) However, I imagine this could be a case that JVM could somehow distinguish between references to c from GC-eligible and non-GC-eligible objects, and therefore mark c as eligible at the same time as b.
Is the behaviour determined by Java Language Specification, or any JVM-related specification? Or is it left for the JVM implementation to decide?