Python memory deallocate

Tim Peters tim.peters at gmail.com
Thu May 11 12:57:47 EDT 2006


[Serge Orlov]
> BTW python 2.5 now returns free memory to OS, but if a program keeps
> allocating more memory with each new iteration in python 2.4, it will
> not help.

No version of CPython ever returns memory to "the OS".  All memory is
obtained via the platform C's alloc() or realloc(), and any memory
"returned" is given back to the platform C's free().  Whether and when
the platform C's free() in turn gives memory back to the OS is
entirely up to the OS and C's implementation of free(), varies across
OSes and platform free() implementations, typically has no easy
answer, and is something Python has no control over regardless.

It's true that Python 2.5 will, in some cases, return more memory to
free() than did previous versions of CPython.  When it does, that may
or may not affect what the OS reports as the process's memory use.



More information about the Python-list mailing list