A survey of 40 major C projects examines how they allocate and release memory, challenging the idea that C code relies exclusively on programmers pairing malloc with free. Only eight projects use malloc/free as their sole allocation strategy, while two avoid those functions entirely. Fifteen use regions somewhere in their code: regions let a program free many allocations at once, rather than freeing each object individually, and seven projects use them as their main strategy. Five primarily use garbage collection, and three primarily use reference counting. The survey covers projects tracked among more than 400 software infrastructure projects, excluding test code, third-party code, and examples.
The findings also complicate assumptions about projects known for careful engineering. SQLite handles all its memory manually, while cURL and Redis are mostly manual, with reference counting used for some objects. Linux and QEMU have recently adopted compiler-extension-based scope cleanup, which automatically releases resources when they leave scope. The survey classifies each project’s main strategy by counting allocation call sites, a useful but limited measure that does not account for allocation sizes or how much memory is handled within regions. seL4 is a special case because it has no heap at all. Overall, the results show that major C projects use a broad mix of memory-management techniques, often combining approaches rather than relying on one system.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.