Writing a .NET Garbage Collector in C# – Part 6: Mark and Sweep

Posted by vyrotek 1 day ago

Counter26Comment3OpenOriginal

Comments

Comment by wsve 19 hours ago

Writing an efficient garbage collector in a garbage collected language is actually very funny to me. Neat project!

Comment by WorldMaker 7 hours ago

It's a relative to self-hosting. If a language can be compiled in itself the compiler also becomes one of the first tests of language compatibility. Similarly, if you can write low-level pieces like a garbage collector in the the higher-level language itself you can maybe save transitions to and from lower level code and help prove the language is useful in lower level scenarios. It's maybe backwards to expectations but a lot of .NET improvements over the years has just been moving low level code from C++ to a low level subset of C# to avoid thread stack transitions and/or gift the JIT and AOT compilers with more tools to inline low level code. There have been experimental GCs in the .NET Runtime written in C# for the exact same reason. There likely will be again.