Why doesn't Python release the memory when I delete a large object?
If you create a large object and delete it again, Python has probably released the memory, but the memory allocators involved don’t necessarily return the memory to the operating system, so it may look as if the Python process uses a lot more virtual memory than it actually uses.
Memory allocation works at several levels in Python. There’s the system’s own allocator, which is what shows up when you check the memory use using the Windows Task Manager or ps. Then there’s the C runtime’s memory allocator (malloc), which gets memory from the system allocator, and hands it out in smaller chunks to the application. Finally, there’s Python’s own object allocator, which is used for objects up to 256 bytes. This allocator grabs large chunks of memory from the C allocator, and chops them up in smal