Garbage Collection Without Unsafe Code

https://fitzgen.com/2024/02/06/safe-gc.html

Article

TL;DR: A Rust GC that avoids unsafe code entirely using a Trace trait and Gc<T> wrapper.

Key Takeaways

  • Gc<T> wrapper plus a derive macro enable safe traced references with no unsafe blocks
  • Eliminates a whole class of GC-related undefined behavior — rare in systems-level GC work
  • Gc<> couples types to the allocator, making adoption and experimentation costly

Discussion

  • [the-smug-one]: Gc<> wrapper ties types to one allocator, making trying a GC painful

    trying out a GC is a pain, as you’re stuck first doing the rewrite of your types

  • [foota]: Found it while removing C FFI unsafe code but chose pointer-mapping instead
  • Main debate: whether Gc<> ergonomic cost is worth the safety guarantee.

Discuss on HN


Type Link
Added Apr 22, 2026
Modified Apr 22, 2026