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

Wong Wah Meng-R32813 r32813 at freescale.com
Thu Mar 7 07:33:23 CET 2013


Python does not guarantee to return memory to the operating system. 
Whether it does or not depends on the OS, but as a general rule, you should expect that it will not.


>>>> for i in range(100000L):
> ...     str=str+"%s"%(i,)


You should never build large strings in that way. It risks being 
horribly, horribly slow on some combinations of OS, Python implementation 
and version.

Instead, you should do this:

items = ["%s" % i for i in range(100000)]
s = ''.join(items)

[] The example is written for illustration purpose. Thanks for pointing out a better way of achieving the same result. Yes it seems so that the OS thinks the piece allocated to Python should not be taken back unless the process dies. :(




More information about the Python-list mailing list