Last Updated: May 22, 2026
CPython's primary memory manager is reference counting: every object carries a counter, and when the counter drops to zero, the object is freed immediately. This is the mechanism that makes Python deterministic: a Cart goes out of scope, its memory is gone before the next line runs. This lesson covers how the counter is maintained, what changes it on each Python operation, why sys.getrefcount always seems off by one, and how this design interacts with the GIL and with non-CPython interpreters.