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

Privacy Overview
Referbruv

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

3rd Party Cookies

This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.