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