In python I have noticed that if you do
mylist = []
for i in range(0,100000000):
mylist.append('something here to take memory')
mylist = []
it would seem the second call
mylist = []
would remove the reference and it would get collected but, as I watch them memory it does not.
when I use
del mylist[:]
it almost deletes everything but a few megs (just looking at the process)
when I use
del mylist[:]
gc.collect()
I would seem to return to the same amount of memory from before the list was created
so…. why does
mylist = []
not work??? Nothing else is referencing it as far as I can tell
How do you measure that?
I’ve made a small test that does not confirm your results.
Here is the source:
The meminfo module used is here: http://gist.github.com/276090
These are the results with mylist=[]:
This are the results with del mylist[:]:
Python may allocate memory for its own heap, but it does not necessarily free it immediately after garbage collection.