I have a simulation code in Python that uses much of memory with set/list/dict data structure. The outline is as follows:
massSimulation
for i in simList:
individualSimulation
individualSimulation.py
// do simulation and get the result.
...
return result
The issue is that it claims memory little by little until it uses more memory (around 12G) than the system can provide (8G) to make the system really slow, the CPU used by python starts 100% then drops very rapidly to almost 0%. If this happens, I kill the python process and start again.
I added the garbage reclaim code in the individudalSimulation.py
, but the results seem to be the same (I didn't measure, just gut feeling).
import gc
gc.collect()
What could be a solution to this problems? How can I enforce python to relinquish all the memory it claims when a method is finished?