title: How does garbage collection and scoping work in C#?
body: <p>I'm learning C# <a href="https://softwareengineering.stackexchange.com/questions/61433/resources-or-advice-useful-coming-to-c-from-python-2-7-1">coming from python</a> and wish to know how the C# garbage collector works - I found that I understood a lot more about python once I figured out what it was doing behind the scenes, and wish to avoid making the sort of noob errors I made at first when learning python. </p>
  
  <p>I've not been able to find any good clear explanations of when an item is garbage collected and am left with questions such as </p>
  
  <ol>
  <li>"What happens to an object when its last reference passes out of scope?" Does that object get garbage collected or is it still there when you pass back into the scope in which it was defined?</li>
  <li>"At what point is the number of refernces decremented?" Leading me to wonder whether it even uses reference counting or some other technique...</li>
  </ol>
  
  <p>Answers to these, or even better a clear consise overview of what's actually going on will win cookies (or upvotes), and even better if your answer compares it to the python way of doing things. I'm not interested in which is better, just the details. Also answers on my original post on <a href="https://softwareengineering.stackexchange.com/questions/61433/resources-or-advice-useful-coming-to-c-from-python-2-7-1">programmers.stackexchange</a> would be much appreciated...</p>