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 shouldexpect 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 outa 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.