The simplest way to integrate a GC in a language seems to be the Boehm garbage collector.

GC types:

  • Conservative and precise (accurate)
  • Tracing and direct


  • Valgrind can be used to check for leaks: valgrind --leak-check=yes ./program
  • Xcode is bundled with leaks utility: leaks --atExit -- ./program




In particular, LLVM provides support for generating stack maps at call sites, polling for a safepoint, and emitting load and store barriers.

Specifying the GC style on a per-function basis allows LLVM to link together programs that use different garbage collection algorithms (or none at all).

All calls to llvm.gcroot must reside inside the first basic block.

It is also important to mark intermediate values with llvm.gcroot. For example, consider h(f(), g()). Beware leaking the result of f() in the case that g() triggers a collection. Note, that stack variables must be initialized and marked with llvm.gcroot in function’s prologue.