title: When is an object eligible for garbage collection?
body: <p>In the book C# 5.0 in a nutshell by Joseph Albahari I found this</p>
  
  <p><img src="https://i.stack.imgur.com/DQBbg.png" alt="enter image description here">
  where it says as soon as you pass the line of code where a variable is last used, the object referenced by it is eligible for garbage collection (That is if no other variable holds a reference to that object). </p>
  
  <p>However according to <a href="http://www.youtube.com/watch?v=rp8PvFvSO_c" rel="noreferrer">this</a> lecture from UC Berkley, as long as a reference to the object exists on the stack, it won't be garbage collected. My understanding is, until the method returns, the variable stays on the stack. Which means any object referenced by it is alive until the method returns. </p>
  
  <p>Is this an error in the book or does java and .net garbage collection work differently?</p>