titto.sebastian
titto.sebastian

Reputation: 531

python list not deallocating memory after clearing the element of the list

I am using lot of list in my long running python script written in python 2.7. I am using pympler to identify leaked memory and I found that the list object memory is being increasing.But I have cleared all list in each iteration. The RES memory is being increasing largely.After 3 minutes of execution time, the script takes 130 MB of RES memory,I have cleared all list and deleted all objects that were referenced in each iteration. I clear list using:

   del list1[:]

I delete objects that were referenced by using:

   obj=demo_class()
   some code
   del obj

Pls help me in reducing the RES memory?

Thank you PyNico,I had tried it by removing the references to the object and using gc.collect() manually,but it had no effect.

I am using 4 dictionaries in my script.when i ran my script using pympler to find memory leakage,I found that the size of list object is increasing incredibly.And these list contains the keys of these dictionary.Is these list in build implementation of python dictionary?.

Upvotes: 0

Views: 1194

Answers (1)

PyNico
PyNico

Reputation: 695

Take a look at this.It explain why the del keyword doesn't clear the memory -> http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm

You should remove all references to your object then use gc.collect()

Upvotes: 1

Related Questions