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.
  • 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.

Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *