Python memory deallocate

Michele Petrazzo michele.petrazzo at gmail.com
Thu May 11 18:07:19 CEST 2006


Heiko Wundram wrote:

> As was said before: as long as you keep a reference to an object, the object's
> storage _will not be_ reused by Python for any other objects (which is
> sensible, or would you like your object to be overwritten by other objects
> before you're done with them?). Besides, even if Python did free the memory
> that was used, the operating system wouldn't pick it up (in the general case)
> anyway (because of fragmentation issues), so Python keeping the memory in an
> internal free-list for new objects is a sensible choice the Python developers
> took here.

This isn't true. Just tried with python 2.5a2 and:

d:\python25\python.exe
>>> a = range(1000 * 100 *100) # 173 MB
>>> del a # 122MB

So now, like you saied, if I try to allocate another memory chunk,
python'll re-use it... But this isn't true:

>>> b = range(100 * 100 * 100) # 126 MB
>>> del b # 122MB
>>> exit() # :)

d:\python25\python.exe
>>> b = range(100 * 100 * 100) # 19 MB

Do why python don't reuse the freed memory and re-allocate 4 MB (126 -
122)?

For me it's a problem...

> --- Heiko.

Bye,
Michele




More information about the Python-list mailing list