Articles → .NET → Garbage Collector
• Allocate memory to resource.
• Initialize the memory to set the initial state of the resource.
• Use the resource.
• Tear down the state of the resource.
• Free the memory.
Click to Enlarge
Phase I: Mark - Find the memory that can be reclaimed.
• GC identifies live application roots.
• It starts walking the roots and graph all the objects reachable from the roots.The objects that are not reachable through the application roots is considered as garbage.
Phase II: Compact - Move all the live objects to the bottom of
the heap, leaving free space at the top.
Garbage Collector performance optimizations
• Weak References