A live coding session implementing reference counting from scratch in C, motivated by the fact that C lacks built-in memory management. The session covers the theory of reference counting (incrementing/decrementing a counter per reference, freeing when count hits zero), its limitations like cyclic references and weak pointers, and a practical application: building a minimal Lisp/S-expression interpreter in C. The code constructs a tagged union for expression types (nil, symbol, integer, pair), builds list constructors with variadic macros, implements a basic evaluator for addition, and demonstrates memory leaks via Valgrind — setting up the motivation for adding reference counting to the allocator. The RC design allocates a counter header before the data payload, with acquire/release operations.

2h 17m watch time

Sort: