Python 2.6 still not giving memory back to the OS...

Chris Withers chris at simplistix.co.uk
Sat Aug 15 07:55:37 EDT 2009


Hi All,

I thought this was fixed back in Python 2.5, but I guess not?

So, I'm playing in an interactive session:

 >>> from xlrd import open_workbook
 >>> b = open_workbook('some.xls',pickleable=0,formatting_info=1)

At this point, top shows the process usage for python to be about 500Mb.
That's okay, I'd expect that, b is big ;-)

 >>> del b

However, it still does now, maybe the garbage collector needs a kick?

 >>> import gc
 >>> gc.collect()
702614

Nope, still 500Mb. What gives? How can I make Python give the memory its 
no longer using back to the OS?

Okay, so maybe this is something to do with it being an interactive 
session? So I wrote this script:

from xlrd import open_workbook
import gc
b = open_workbook('some.xls',pickleable=0,formatting_info=1)
print 'opened'
raw_input()
del b
print 'deleted'
raw_input()
gc.collect()
print 'gc'
raw_input()

The raw inputs are there so I can check the memory usage in top.
Even after the gc, Python still hasn't given the memory back to the OS :-(

What am I doing wrong?

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk



More information about the Python-list mailing list