- Garbage Collector is an important component, which is available in most of the high-level programming languages
- GC is responsible for cleaning of memory when the resources placed on the memory are no longer required by the program execution.
- In C#, Garbage Collector is provided by the CLR (Common Language Runtime) which also provides an environment for .NET programs to run.
- GC monitors the objects created during program execution and releases the memory once they’re no longer referenced by the program. It also takes care of the heap memory.
- It tags the objects into Gen 0, Gen 1, and Gen 2 based on how frequently they’re accessed. Gen 0 are frequently collected, while Gen 2 is less frequently done.
- GC also can’t work on unmanaged code. It’s the developer’s responsibility to ensure their disposal.
- Developers can call GC by using the Dispose method provided by the IDisposable interface.
What is the importance of Garbage Collection?
Garbage Collector is an important component, responsible for cleaning of memory when the resources are no longer required by the program.