What is garbage collection in C#?
Explain how garbage collection works in C#
Garbage collection generations - Gen0
Garbage collection generations - Gen1
Garbage collection generations - Gen2
Garbage collection process
Marking
Garbage collector identifies which objects can be cleaned and marks the live objects
Sweeping
Garbage collector reclaims the memory occupied by objects that are marked as live
Compacting
Objects that survive Gen0 are promoted to Gen1, etc.
What is the purpose of the System.GC class in C#?
What is the difference between managed and unmanaged resources in the context of garbage collection?
Managed resources
Objects under control of .NET runtime
Subject to garbage collection
Unmanaged resources
External resources such as database connections
Require explicit cleanup
How can you force garbage collection in C#?
What are memory leaks, and how can you avoid them in C#?
To avoid:
Explain the concept of the “root” in garbage collection.
What is the impact of garbage collection on application performance?
What are weak references in C#, and when are they useful?