Garbage collection

Nick Craig-Wood nick at craig-wood.com
Wed Mar 21 15:30:08 EDT 2007


Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> wrote:
>  Or you could just have an "object leak" somewhere. Do you have any
>  complicated circular references that the garbage collector can't resolve?
>  Lists-of-lists? Trees? Anything where objects aren't being freed when you
>  think they are? Are you holding on to references to lists? It's more
>  likely that your code simply isn't freeing lists you think are being freed
>  than it is that Python is holding on to tens of megabytes of random
>  text.

This is surely just the fragmented heap problem.

It is a hard problem returning unused memory to the OS since it
usually comes in page size (4k) chunks and you can only return pages
on the end of your memory (the sbrk() interface).

The glibc allocator uses mmap() for large allocations which *can* be
returned to the OS without any fragmentation worries.

However if you have lots of small allocations then the heap will be
fragmented and you'll never be able to return the memory to the OS.

However that is why we have virtual memory systems.

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list