title: How many objects are eligible for the garbage collector?
body: <p>Could you please check my solution to the question: "How many objects are eligible for the garbage collector on the line (// custom code)?"</p>
  
  <pre><code>class Dog {
      String name;
  }
  
  public class TestGarbage {               
      public static void main(String[] args) { 
          Dog d1 = new Dog();                
          Dog d2 = new Dog();                
          Dog d3 = new Dog();                
  
          d1 = d3;                                   // line 1
          d3 = d2;                                   // line 2
          d2 = null;                                 // line 3
  
          // custom code
      }
  }
  </code></pre>
  
  <p>What I know from the documenation: "The object will not become a candidate for garbage collection until all references to it are discarded."</p>
  
  <p>Objects and references: (Where A, B and C are the Objects created)</p>
  
  <pre><code>d1 -&gt; A
  d2 -&gt; B
  d3 -&gt; C
  ------- d1 = d3 ------
  d1 -&gt; C
  d2 -&gt; B
  d3 -&gt; C
  ------- d3 = d2 ------
  d1 -&gt; C
  d2 -&gt; B
  d3 -&gt; B
  ------- d2 = null ------
  d1 -&gt; C
  d2 -&gt; null
  d3 -&gt; B
  </code></pre>
  
  <p>A is eligible to delete, so we can say that there is ONLY ONE object which is eligible for the garbage collector!</p>
  
  <p>Is this approach right?</p>