title: Memory leaks in .NET
body: <p>What are all the possible ways in which we can get memory leaks in .NET?</p>
  
  <p>I know of two:</p>
  
  <ol>
  <li>Not properly un-registering <a href="http://diditwith.net/PermaLink,guid,fcf59145-3973-468a-ae66-aaa8df9161c7.aspx" rel="nofollow noreferrer">Event Handlers/Delegates</a>.</li>
  <li>Not disposing dynamic child controls in Windows Forms:</li>
  </ol>
  
  <p>Example:</p>
  
  <pre><code>// Causes Leaks  
  Label label = new Label();  
  this.Controls.Add(label);  
  this.Controls.Remove(label);  
  
  // Correct Code  
  Label label = new Label();  
  this.Controls.Add(label);  
  this.Controls.Remove(label);  
  label.Dispose();
  </code></pre>
  
  <p><strong>Update</strong>: The idea is to list common pitfalls which are not too obvious (such as the above). Usually the notion is that memory leaks are not a big problem because of the garbage collector. Not like it used to be in C++.</p>
  
  <hr>
  
  <p>Great discussion guys, but let me clarify... by definition, if there is no reference left to an object in .NET, it will be Garbage Collected at some time. So that is not a way to induce memory leaks.</p>
  
  <p>In the managed environment, I would consider it a memory leak if you had an unintended reference to any object that you aren't aware of (hence the two examples in my question).</p>
  
  <p><strong>So, what are the various possible ways in which such a memory leak can happen?</strong></p>