Apex › Systems & OS

How reference counting frees memory

The deterministic counterpart to tracing GC, used by C++ shared_ptr, Rust’s Rc/Arc, Swift’s ARC, and CPython. Each object counts its references: copy one and it increments, drop one and it decrements, and the instant it hits zero the object is freed — no collector, no pause. Then the fatal flaw: two objects that point at each other keep their counts at 1 forever and leak. Drop the root, watch the cycle leak, then make an edge weak and watch it all reclaim.

More in Systems & OS