How do you measure that?
I've made a small test that does not confirm your results.
Here is the source:
import meminfo, gc, commands
page_size = int(commands.getoutput("getconf PAGESIZE"))
def stat(message):
s = meminfo.proc_stat()
print "My memory usage %s: RSS: %dkb, VSIZE: %dkb" % (
message, s['rss']*page_size/1024, s['vsize']/1024)
mylist = []
stat("before allocating a big list")
for i in range(0,3000000):
mylist.append('something here to take memory')
stat("after allocating big list")
### uncomment one of these:
mylist = []
# del mylist[:]
stat("after dropping a big list")
gc.collect()
stat("after gc.collect()")
gc.collect()
stat("after second gc.collect()")
gc.collect()
stat("after third gc.collect()")
The meminfo module used is here: http://gist.github.com/276090
These are the results with mylist=[]:
My memory usage before allocating a big list: RSS: 3396kb, VSIZE: 7324kb
My memory usage after allocating big list: RSS: 50700kb, VSIZE: 55084kb
My memory usage after dropping a big list: RSS: 38980kb, VSIZE: 42824kb
My memory usage after gc.collect(): RSS: 38980kb, VSIZE: 42824kb
My memory usage after second gc.collect(): RSS: 38980kb, VSIZE: 42824kb
My memory usage after third gc.collect(): RSS: 38980kb, VSIZE: 42824kb
This are the results with del mylist[:]:
My memory usage before allocating a big list: RSS: 3392kb, VSIZE: 7324kb
My memory usage after allocating big list: RSS: 50696kb, VSIZE: 55084kb
My memory usage after dropping a big list: RSS: 38976kb, VSIZE: 42824kb
My memory usage after gc.collect(): RSS: 38976kb, VSIZE: 42824kb
My memory usage after second gc.collect(): RSS: 38976kb, VSIZE: 42824kb
My memory usage after third gc.collect(): RSS: 38976kb, VSIZE: 42824kb
Python may allocate memory for its own heap, but it does not necessarily free it immediately after garbage collection.