title: Java: setting a reference to null won't affect the object
body: <p>I've got a simple question. In this code below, why is s3's value still printed although I set it to null before. It seems gargbage collector won't get called.</p>
  
  <pre><code>public class Test {
      public static void main(String[] args) {
           String s1 = "abc", s2 = "def", s3 = "ghj";
  
           String sarr[] = {s1, s2, s3};
           s3 = null;
  
           System.gc(); 
  
           for(int i = 0; i &lt; sarr.length; i++) {
               System.out.print(sarr[i] + " "); //prints abc def ghj
           }
      }
   }
  </code></pre>
  
  <p>Any thoughts would be appreciated.</p>