> I'm a bit fuzzy on this, but I don't think there _is_ a > practical way to "return memory to the OS" in many OSes.
That's not true at all. Most C libraries these days manage to return memory to the operating system. On Win32 (which the OP is most likely to use), the operating system offers the VirtualFree function to release memory to the operating system. In MSVCRT, the small block allocator will invoke VirtualFree inside __sbh_free_block, when a block group becomes completely free on the C level; likewise, _heap_free_region invokes VirtualFree, so does _heapmin_region. In glibc 2 on Linux, public_fREe will invoke munmap to release the memory to the operating system if the chunk being freed was mmap'ed. glibc allocates chunks greater than mmap_threshold with mmap, which defaults to 128kiB - so Python's obmalloc arenas fall under that algorithm. For small blocks, glibc releases topmost memory through sbrk when it gets more than M_TRIM_THRESHOLD bytes (defaults to 128kiB as well). This algorithm isn't used when MORECORE_CANNOT_TRIM is defined, which it would only on systems where sbrk does not support negative arguments. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list