2006-09-25

GC.Collect not the solution

Many times i have come to situations where the memory usage in my program spirals out of control. Always i think it is a problem with anything but my program. I test the cleanups of the 3rd party libraries, and every other little thing. Then i resort to put GC.Collect statements around, thinky that it will magically free memory.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

Then i go searching for how to debug these things:
http://blogs.msdn.com/tess/archive/2006/09/06/742568.aspx
http://blogs.msdn.com/tess/archive/2006/08/11/695268.aspx

Finally i get stuck into reviewing my code with a fine tooth comb, and find one thing that was causing the leak, static array on a singleton, used in temporary processing, that didnt get cleared.