Skip to content- Sources: primary, discussion
- Summary: Phil Eaton at The Consensus counted allocation call sites in 40 major C projects, excluding tests and vendored code. Eight, including SQLite, HAProxy and zlib, use only malloc and free. Seven, including PostgreSQL, nginx and httpd, mostly use regions, while Ruby, Julia, Emacs, OCaml and Lua mostly use garbage collection and CPython, PHP and Perl mostly use reference counting. Linux and QEMU have started using compiler-backed scope cleanup such as __free(kfree) and g_autofree.
- Why it matters: It gives concrete, named examples of region, refcount and scope-cleanup patterns in codebases you may embed or patch, such as Lua, Neovim, Git and PostgreSQL.
- Background: A region or arena allocator hands out objects from a pool that is freed in one call, so code does not track each object's lifetime. PostgreSQL's memory contexts (palloc) and nginx pools are the best-known examples. Scope cleanup relies on the GCC and Clang cleanup attribute, which runs a function when a variable leaves scope, giving C a limited form of RAII.