memory recycling/garbage collecting problem

Christian Heimes lists at cheimes.de
Tue Feb 17 16:59:33 CET 2009


Yuanxin Xi wrote:
> Could anyone please explain why this happens?  It seems some memory
> are not freed.  I'm running into problems with this as my program is
> very memory cosuming and need to frequently free some object to reuse
> the memory.  What is the best way to free the memory of b completely
> (i.e. back to the status as b was created)?  I'm using Python 2.5.2

Python uses malloc() and free() to allocate memory on the heap. Most
malloc() implementations don't give back memory to the system. Instead
the memory segment is still assigned to the process. In order to give
back memory to the system pool, a memory manager has to use mapped
memory (mmap()) instead of increasing the heap by changing the data
segment size with brk(). This isn't a Python flaw but a general issue
with malloc() based memory management. [1]

By the way Python has its own memory management system on top of the
system's malloc() system. The memory arena system is explained in great
detail in the file obmalloc.c [2].

Christian

[1] http://en.wikipedia.org/wiki/Malloc#Implementations
[2]
http://svn.python.org/view/python/branches/release25-maint/Objects/obmalloc.c?revision=65261&view=markup




More information about the Python-list mailing list