About

Sunday, September 29, 2019

Basic garbage collection

In the common language runtime (CLR), the garbage collector serves as an automatic memory manager. 
It provides the following benefits:
  • Enables you to develop your application without having to manually free memory for objects you create.
  • Allocates objects on the managed heap efficiently.
  • Reclaims objects that are no longer being used, clears their memory, and keeps the memory available for future allocations. Managed objects automatically get clean content to start with, so their constructors do not have to initialize every data field.

Garbage Collection in C# Interview Question 


What is Garbage Collection

Garbage collection is one of most important future in the .Net Framework environment

Futures : 

1. When we have a class that represents an object in the runtime that allocates a memory space in the heap memory.

2. When there isn't enough memory to allocate an object, the GC must collect and dispose of garbage memory to make memory available for ne allocations


3. You can force garbage collection either to all the three generations or to a specific generation using the GC.Collect() method the GC.Collect() Method is overloaded you can call it without any parameters or event by passing the generation number you would like to the garbage collector to collect.

4 it determines when an instanciated class is no longer in using and reclaims memory.

5. The .Net  language does not do so the CLR does so. that's why its called "automatic garbage collection"

There are three type in generation :