title: Garbage collection of previously assigned object
body: <p>Consider the following scenario:</p>
  
  <pre><code>String dude = "Harold";
  
  //some stuff
  
  dude = "Kumar";
  </code></pre>
  
  <p>Once <code>dude</code> is assigned its second value of "Kumar", a whole new object separate from "Harold" comes into existance.  What I am wondering is, since there is clearly no use for "Harold" any more, is it garbage collected instantly or at some later time when the JVM deems it appropriate?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Just because <code>dude</code> has been set to a new value (object) does not necessarily mean all reference to the old object have been eliminated.  If another reference invokes <code>dude</code> after "Harold" and before "Kumar", it will obviously retain the "Harold" object:</p>
  
  <pre><code>String dude = "Harold";
  
  //some stuff
  
  String interim = dude;
  
  dude = "Kumar";
  
  System.out.println("dude = " + dude);
  System.out.println("interim = " + interim);
  </code></pre>
  
  <p>prints</p>
  
  <pre><code>dude = Kumar
  interim = Harold
  </code></pre>
  
  <p>So there are more considerations than I originally envisioned therefore the initial value doesn't necessarily have to be out of scope after the change.</p>