title: when an object is eligible for a garbage collector?
body: <p>consider this sample code:</p>
  
  <pre><code>1.  public class GC {
  2.      private Object o;
  3.      private void doSomethingElse(Object obj) { o = obj; }
  4.      public void doSomething() {
  5.          Object o = new Object();
  6.          doSomethingElse(o);
  7.          o = new Object();
  8.          doSomethingElse(null);
  9.          o = null;
  10.     }
  11. }
  </code></pre>
  
  <p>When the doSomething method is called, after which line does the Object created in line
  5 become available for garbage collection? </p>
  
  <p>A. Line 5</p>
  
  <p>B. Line 6</p>
  
  <p>C. Line 7</p>
  
  <p>D. Line 8</p>
  
  <p>E. Line 9</p>
  
  <p>F. Line 10</p>
  
  <p>Answer: D</p>
  
  <p>why D? it's true that when Line 6 is executed the object created in Line 5 is now referenced by the instance var o and the local var o and when Line 8 is executed the object now is referenced by only the local ref var o, so why the answer is D and what happens after Line 9 is executed?? thanks.</p>