The best ressources to learn about OCaml GC


Having a thirst for culture and being a complete stranger to anything to do with memory in OCaml, I’d like to learn how its garbage collector works, and garbage collectors in general in fact, why it’s useful, what my life as an OCaml programmer would be like without it (I have a small idea but I’d like to start from scratch voluntarily).

What resources would you recommend?

At the risk of tooting my own horn, you may find the Real World OCaml chapter on the OCaml garbage collector useful (I recommend starting a few chapters earlier with the memory layout and FFI, and then moving onto how the GC works).

This is a description of the OCaml 4.14 GC, and the OCaml 5 one is substantially different since it adds support for shared-memory parallelism. The closest description of the OCaml 5 GC is from the “Retrofitting Parallelism onto OCaml” paper, with other documentation efforts ongoing (I’m planning on working this summer to update the RWO content to OCaml 5, but it’s not there yet).


Since you are also asking about GCs in general, the GC Handbook is a great resource. Its 2nd edition comes out this month.


There’s a great, beginner friendly Signals and Threads episode about memory management and garbage collection: Signals and Threads | Memory Management