Saturday, June 8, 2013

When does Garbage Collection Run?

Garbage Collection is completely controlled by the .Net runtime, generally we need not force the Garbage Collector to run, as this will lead to degradation in performance, but still you can force the Garbage Collector to run by calling the GC.Collect method.

The .Net runtime decides on the best time to run the Garbage Collection by evaluating various parameters on the available memory and other factors, the following are some of the situations when the .Net runtime triggers Garbage Collection.
1. When the system is running low on Physical Memory.
2. When the Managed Heap is running out of memory and it becomes difficult to allocate memory to the new objects that get created.
3. When GC.Collect() is explicitly called from the application.

Search Flipkart Products:
Flipkart.com

No comments: