#738 – You Shouldn’t Explicitly Force Garbage Collection
December 18, 2012 1 Comment
For purposes of understanding what happens when objects get garbage collected, you can force garbage collection to happen by calling the GC.Collect method. Calling this method in production code is almost always a bad idea.
The garbage collector is finely tuned for maximum performance and when you call GC.Collect explicitly, you disturb that tuning and make the garbage collector less efficient.
When you feel that you need to call GC.Collect in order to explicit release objects, it’s generally a sign of poor design in some area of your code. (E.g. Not making proper use of a Dispose method on an object when you are done using it).