Garbage collection working improperly?

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Nov 21 09:02:03 EST 2003


"Oliver Walczak" <oliver.walczak at momatec.de> wrote in
news:mailman.953.1069412317.702.python-list at python.org: 

> Builds up a great list in memory and immediately deletes it.
> Unfortunately the task manager shows me that i allocated about 155MB
> in memory before del(), but del only releases about 40MB of them so
> i'm leaving about 117 MB of reserved memory after deleting the list.
> I'm using python 2.2.3 on WinXP.
> Any ideas about that? How can i dealloc the left memory space?

You cannot, but it shouldn't matter. If you aren't using it, then it will 
eventually get paged out and occupy space in the swapfile, but the physical 
memory will be allocated to other processed.

Small objects get handled specially by Python's memory allocation, and the 
memory used for small objects will never be returned to the operating 
system (until the process terminates). Its a trade off, because it means 
that allocating the small objects is much faster, but the cost is extra 
swap space used, not extra physical memory.

If it really matters to you to allocate a massive spike of memory then 
release it all, you could try extracting the memory hungry code out into a 
separate process that can terminate once it has finished whatever 
calculation you are doing. That way all the memory really would be 
released.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list