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

Chris Withers chris at
Sat Aug 15 13:55:37 CEST 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()

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'
del b
print 'deleted'
print 'gc'

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?


Simplistix - Content Management, Batch Processing & Python Consulting

More information about the Python-list mailing list