Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64)

Isaac To isaac.to at gmail.com
Sat Mar 9 10:02:17 EST 2013


In general, it is hard for any process to return the memory the OS allocate
to it back to the OS, short of exiting the whole process.  The only case
that this works reliably is when the process allocates a chunk of memory by
mmap (which is chosen by libc if it malloc or calloc a large chunk of
memory), and that whole chunk is not needed any more.  In that case the
process can munmap it.  Evidently you are not see that in your program.
What you allocate might be too small (so libc choose to allocate it using
another system call "sbrk"), or that the allocated memory also hold other
objects not freed.

If you want to reduce the footprint of a long running program that
periodically allocates a large chunk of memory, the "easiest" solution is
to fork a different process to achieve the computations that needs the
memory.  That way, you can exit the process after you complete the
computation, and at that point all memory allocated to it is guaranteed to
be freed to the OS.

Modules like multiprocessing probably make the idea sufficiently easy to
implement.


On Sat, Mar 9, 2013 at 4:07 PM, Wong Wah Meng-R32813
<r32813 at freescale.com>wrote:

>
>
>         If the memory usage is continually growing, you have something
> else that is a problem -- something is holding onto objects. Even if Python
> is not returning memory to the OS, it should be reusing the memory it has
> if objects are being freed.
> --
> [] Yes I have verified my python application is reusing the memory (just
> that it doesn't reduce once it has grown) and my python process doesn't
> have any issue to run even though it is seen taking up more than 2G in
> footprint. My problem is capacity planning on the server whereby since my
> python process doesn't release memory back to the OS, the OS wasn't able to
> allocate memory when a new process is spawn off.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130309/c5231c21/attachment.html>


More information about the Python-list mailing list