c# memory allocation and deallocation patterns

Posted by Neal on Stack Overflow See other posts from Stack Overflow or by Neal
Published on 2010-04-27T00:09:37Z Indexed on 2010/04/27 0:13 UTC
Read the original article Hit count: 433

Since C# uses Garbage Collection. When is it necessary to use .Dispose to free the memory?

I realize there are a few situations so I'll try to list the ones I can think of.

  1. If I close a Form that contains GUI type object, are those objects dereferenced and therefore will be collected?
  2. If I create a local object using new should I .Dispose of it before the method exits or just let the GC take care of it? What is good practice in this case?
  3. Are there any times in which forcing a GC is understandable?
  4. Are events collected by the GC when it's object is collected?

© Stack Overflow or respective owner

Related posts about c#

Related posts about memory-management