Also note that C programs can not free certain amounts of memory too. Since CPython is written in (you guessed it) C, it has the same problems as C programs.
On 6/27/06, Brian Fisher <[EMAIL PROTECTED]> wrote:
On 6/26/06, Bob Ippolito <[EMAIL PROTECTED]> wrote: > > ... also one thing to note when trying to track down mem usage of a > > game, I remember that python never freed stuff in favor of keeping > > allocated memory in a pool (at least that is true with 2.3) so that > > .... > > That's not really true and it never has been. Python does keep some > pools of memory around forever to allocate small objects > You are right, I worded my post terribly - I didn't mean that python never freed memory, I meant there is some memory that python never freed. The small objects python maintains pools for includes ints and parts of dictionaries and lists and all kinds of common python objects (which is why it's worth it to keep pools of some kind) - so if you at some point called range(1000000) for instance, you just made the pool grow to near 100MB (in addition to whatever non-pooled mem might be allocated) and the pool won't shrink until your process ends. pretty much any giant list or dictionary can do that (I've seen the Task Manager mem usage for python get fixed at about 400MB after pickling a 400 element dictionary where each element was a 400 element dictionary) my point is simply that if you see a huge memory usage by a python app and you wonder how you could possibly be using that much memory at that point in time, it may be the python process pooling. > ... but Python definitely frees memory. Operating > systems may or may not actually report that memory as freed when > Python calls free() though. > In addition to whatever your c free and the OS are doing, that pooling thing can mean python squats on memory. evidently there was a patch applied for 2.5, though http://evanjones.ca/python-memory.html here's a stupid example you can use to see this effect (just check mem usage while the script is sleeping): ------------ import time sleep_time = 10 print 'allocating giant list' a = range(10000000) print "sleeping %d seconds" % sleep_time time.sleep(sleep_time) print 'deleting giant list' del a print "sleeping %d seconds" % sleep_time time.sleep(sleep_time)