how to explain this memory usage

Alex Martelli aleaxit at yahoo.com
Thu Apr 26 11:59:33 EDT 2001


"Andrew Kuchling" <akuchlin at mems-exchange.org> wrote in message
news:3dpudzu4ij.fsf at ute.cnri.reston.va.us...
> javalist <javalist at 21cn.com> writes:
> >        also the interpreter has 20M in memory,but seems python knows
they are
> >        pointing nothing and reuse these 20M when I try again allocating
more
> >        object in python,it didn't increase memory until the first 20M is
> >        occupied by the new allocated object
>
> This is also dependent on your platform's malloc.  The malloc used on
> Linux, for example, uses mmap() for allocations above a given size,
> and on freeing an mmap()'ed area, the process size drops.  For
> example, I just tried creating a 20Mb string, watched the process size
> jumped appropriately, then deleted it and watched the process go back
> to around 2Mb.

I just tried and confirmed Python 2.0 works this way on Windows NT,
too.  As you say, it does depend on the platform library.

> 20Mb of smaller objects probably won't have this
> pleasant predictability.  I'm not sure how enabling pymalloc would
> change this picture.

On NT,

>>> x=[str(i) for i in range(100000)]

makes python.exe's VM Size stat in the Task Manager jump up to
over 7000K, and a "del x" now makes it jump back down to 2200K
(was below 1000K before).  Repeating this a few time confirms
identical numbers (nothing's being leaked here).


Alex






More information about the Python-list mailing list