title: The life time of an object in a garbage collected environment
body: <p>My question is a simple one and is specifically targeted at C# with CLR.</p>
  
  <p>First of all we got code snippet 1:</p>
  
  <pre><code>public void f(SomeClass sc)
  {
     anExistingInstance.FieldOfSomeClass = sc;
  }
  </code></pre>
  
  <p>and now code snippet 2:</p>
  
  <pre><code>public void f()
  {
    SomeClass sc = new SomeClass();
    anExisitingInstance.FieldOfSomeClass = sc;
  }
  </code></pre>
  
  <p>At code 1, when the method which called <code>f</code> and defined <code>sc</code> is over, I'm guessing that <code>sc</code> gets released and that's why <code>anExisitingInstance.FieldOfSomeClass</code> is no longer valid.</p>
  
  <p>My question is why doesn't the same thing happen at code 2 but with the method <code>f</code> itself? Why when <code>f</code> is done, <code>anExisitingInstance.FieldOfSomeClass</code> still holds a correct value?</p>