how to explain this memory usage

Steve Holden sholden at holdenweb.com
Thu Apr 26 09:41:00 EDT 2001


"javalist" <javalist at 21cn.com> wrote in message
news:mailman.988284459.28229.python-list at python.org...
> Hello python-list,
>
>         in the python 2.0 interpreter,I write some code to make the
interpreter
>         allocate more than 20M memory,and then I del all the object that I
>         create,but python still using that 20M memory,I try import gc,and
then
>         use gc.collect,no good.python has 20M in memory still.
>         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
>
> Best regards,
>  javalist                          mailto:javalist at 21cn.com
>
QUALIFICATION: You may get better, conflicting, advice from those who have
studied the code, but...

The point of garbage collection is to release memory occupied by deleted
objects back to the Python interpreter *for re-use to store new objects*. If
Python is like most other language interpreters, it will never say to itself
"Why, I've just reclaimed 20MB of memory, perhaps the OS would like some of
that back, let's see".

In other words, the memory allocated to a process running a Python program
moves upwards from the current high-water mark, never downwards.

It's actually quite unusual for programs to give back memory to the OS in
any case, except the special one of "I've finished, you can have it ALL".

regards
 Steve





More information about the Python-list mailing list