Writing a .NET Garbage Collector in C# – Part 6: Mark and Sweep
Summary
Part 6 continues the author's project to implement a .NET garbage collector in C#. It details the mark phase starting from roots (locals, thread-static storage, GC handles, finalization queue) and introduces ScanContext, the GcScanRoots callback, and conservative mode notes. It then outlines a DFS-based marking pass and a sweeping phase that clears unreachable objects, reuses memory with free objects to keep the heap walkable, and references prior parts for heap layout and reference discovery.