What is the purpose of the GC (Garbage Collector) in .NET? How does it work?

Mid C#

Answer

The Garbage Collector (GC) frees unused heap objects automatically.

It uses generations (Gen0, Gen1, Gen2) to optimize collection of short-lived and long-lived objects.

The GC pauses execution, removes unreachable objects, and compacts memory.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice