
🧠 Understanding Python memory helps explain why freeing an object does not always reduce the memory reported by the operating system.
In CPython, small objects typically use pymalloc, which organizes reusable blocks into pools and arenas. Larger objects usually go through the system’s malloc allocator. When a small object is freed, Python may keep its space for reuse; an arena is returned to the system only when it is completely empty.
Object cleanup combines reference counting—an object is released when nothing references it—with garbage collection, which detects cycles that reference counting alone cannot resolve.
💡 Explanation in a nutshell#
Think of a shared storage box: emptying one compartment does not mean the whole box is returned. Python may keep that space for later. To control how long an object stays alive, it matters how many references still point to it.
More information at the link 👇
