memory recycling/garbage collecting problem

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Feb 17 02:26:28 EST 2009


On Mon, 16 Feb 2009 23:21:16 -0600, Yuanxin Xi wrote:

> I'm having some problems with the memory recycling/garbage collecting of
> the following testing code:
> 
>>>> a=[str(i) for i in xrange(10000000)]
> This takes 635m/552m/2044 memory (VIRT/RES/SHR)
> 
>>>> b={}
>>>> for i in xrange(10000000):
> ...     b[str(i)]=i
> 
> Then the memory usage increased to 1726m/1.6g/2048
> 
>>>> del b
> I expect the memory usage drop to the ammount before b was
> created(635m/552m/2044), but it's actually 1341m/1.2g/2048
> 
> Could anyone please explain why this happens?  It seems some memory are
> not freed.

It seems the memory is not given back to the operating system.  This 
doesn't mean that it is not freed by Python and can't be used again by 
Python.  Create the dictionary again and see if the memory usage rises 
again or if it stays stable.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list