Garbage Collection

What is Garbage Collection(GC)?

The garbage collector (GC) manages the allocation and release of memory in .NET framework.  Garbage collection is one of the responsibilities of CLR only. Garbage collector will dispose this employee object automatically when it is no longer needed. G…

What are Generations in garbage collection?

Garbage collection release the objects which are no longer needed. .NET framework has a mechanism to decide which objects are no longer needed and that mechanism we call generations. Generation is a mechanism to collect the short-lived objects more f…

What is the difference between “Dispose” and “Finalize”?

Both Dispose and Finalize methods are used to release the unmanaged objects which are no longer required. Finalize method is called automatically by the garbage collector. But the Dispose method is called explicitly by the code to release any unmanage…

What is the difference between “Finalize” and “Finally”?

Finalize method is used for garbage collection. So before destroying an object this method is called as part of clean up activity by GC. Finally block is used in exception handling for executing the code irrespective of exception occurred or not. Fina…

Can we force Garbage Collector to run?

Yes, by calling GC.COLLECT() method we can force garbage collector to run, but this is not recommended, instead use Dispose method. However, you can suggest to the GC that it might be a good time to perform garbage collection by using the GC.Collect()…

Load More
That is All