title: Garbage collection on a local variable
body: <p>I'm a C++ programmer entering the world of Java.  And I cannot get rid of the bad feeling of having to let the Java garbage collector do my cleaning.</p>
  
  <p>How, for example, will this code behave in Java?</p>
  
  <pre><code>public void myFunction() {
      myObject object = new myObject();
      object.doSomething();
  }
  </code></pre>
  
  <p>Will the local variable object be deleted when myFunction() exits?</p>
  
  <p>Do I have to set object to null before exiting, or will it be out of scope and be deleted by the GC?  Or, at worst, will it leak like it would in C++?</p>