title: Garbage Collector unexpected output
body: <p>I can't understand what's happening here</p>
  
  <pre><code>public class UnderstandGC {
  public class Inner1
  {
      String name=new Inner2().name;
      public void finalize()
      {
          System.out.println("Inner1 -&gt; I am Dead");
      }
  }
  public class Inner2
  {
      public String name="Inner2";
      public void finalize()
      {
          System.out.println("Inner2 -&gt; I am Dead");
      }
  }
  public void finalize()
  {
      System.out.println("Main -&gt; I am Dead");
  }
      public static void main(String[] args) {
          UnderstandGC ugc=new UnderstandGC();
  Inner1 inner1=ugc.new Inner1();
  //System.out.println("hello");      //1
  
  Runtime.getRuntime().gc();         
  
  
      }
  }
  </code></pre>
  
  <p>Output expected:
  <code>Inner2 -&gt; I am Dead</code> bcoz object of Inner2 instantiated as field reference in Inner1 has no local references from the main thread runtime stack. </p>
  
  <p>Output Observed:  <strong>nothing</strong></p>
  
  <p>The interesting observation is if I include comment <code>//1</code> in my code it works fine. Can't understand what's happening.</p>