Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)
I have designed a python code that will generate an object in a loop and in every iteration overwrites this object with a new one of the same type. This method should be done 10.000 times, and Python takes up 7MB of memory every moment until my 3GB RAM is used. Kindly show me a way to remove the objects from memory?

1 Answer

0 votes
by (108k points)

See, your task basically depends on the properties of the object you are designing and what else you're doing with it in the loop. If the object does not produce circular references, it should be deallocated on the next loop. For example, the code

for x in range(100000):

  obj = " " * 10000000

The above will not result in ever-increasing memory allocation.

For more information regarding the same, do refer to the python training course that will help you out in a better way.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 15, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Jun 8, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...