title: Memory Leak questions
body: <p>I've been reading a lot about this since I've been asked to fix a C# application that has memory leaking problems, but I haven't found an answer for these 2 issues:</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>   private static ArrayList list = new ArrayList();
  
     public void Function()
     {
       list.add(object1);
       list.add(object2);
  
       //didn't call clear() prior to reusing list
       list = new ArrayList();
     }
  </code></pre>
  
  <p>Since the list wasn't cleared before creating a new one, will this generate some sort of garbage that won't be released after the static list itself is disposed?</p>
  
  <p>The second issue is regarding Form.Dispose(). I see that a lot of controls available on designer view (i.e. labels, picture boxes) require disposing. It's seems as though calling Dispose() on a Form causes all of these types of controls to be disposed also (correct me if I'm wrong), which is odd since the designer adds an overriden <strong>void Dispose(bool disposing)</strong> method which does no such thing. I'm assuming that this happens at the <strong>void Dispose(bool disposing)</strong> method of the base Form class.</p>
  
  <p>The problem with the above is that it is not very clear to me what I need to do to ensure that all of the Form's resources are disposed correctly. I do not understand how the Form knows which objects it needs to dispose. For example, if in my form I have a field which is a custom IDisposable object, will the Form know that it needs disposing? Or should I add the code necessary to release the object myself?</p>
  
  <p>Also, if I do need to add the code to dispose certain objects, then how do I deal with the fact that the designer has already overriden the <strong>void Dispose(bool disposing)</strong> method? Should I edit the designer generated code or is there a cleaner way to do this?</p>
  
  <p>I hope that this wasn't to confusing, it's a bit hard to explain. Thanks</p>