How can you force Garbage Collection

The GC.Collect method of the garbage collection GC class can be used to force garbage collection. The GC.Collect method may be used if there is a significant reduction in the amount of memory being used at a defined point in an application's code.

The garbage collector suspends all threads that are currently in the process of execution, before it performs a collection. Frequent calls to GC.Collect method may create performance issues. In most cases the optimizing engine in the garbage collector (which determines the best time to run a garbage collection) is better at determining the best time to perform a collection. 

In general, calls to any of the collect methods should be avoided, and the garbage collector should be allowed to run independently.

No comments:

Post a Comment