I have a few related questions regarding memory usage in the following example.
If I run in the interpreter,
foo = ['bar' for _ in xrange(10000000)]
the real memory used on my machine goes up to
80.9mb. I then,
real memory goes down, but only to
30.4mb. The interpreter uses
4.4mbbaseline so what is the advantage in not releasing
26mbof memory to the OS? Is it because Python is "planning ahead", thinking that you may use that much memory again?
Why does it release
50.5mbin particular - what is the amount that is released based on?
Is there a way to force Python to release all the memory that was used (if you know you won't be using that much memory again)?
This question is different from How can I explicitly free memory in Python?
because this question primarily deals with the increase of memory usage from baseline even after the interpreter has freed objects via garbage collection (with use of
gc.collect or not).