Page 1 of 1

Opensim memory leak during for loop

Posted: Thu Dec 03, 2020 9:05 pm
by mohsensh91
Hi,
I'm trying to run a for loop over a OpenSim analyze tool in python. I have to run over 100000 kinematic instances with the analyzing tool, but after 1000 instances the memory will be filled and my script is crashed. Is there any way we to resolve the issue? I tried to del the create osim.AnlayzeTool after each instance but it did not work!

The memory keep increasing linearly after each iteration.
[/code]
def run_analyze(self, ik_file, analyze_result_folder):
self.analyzeTool = osim.AnalyzeTool(self.analyze_setup_file)
motCoordsData = osim.Storage(ik_file)
initial_time = motCoordsData.getFirstTime()
final_time = motCoordsData.getLastTime()
start = [i for i, c in enumerate(ik_file) if c=='/'][-1]+1
name = ik_file[start:][:-4]
self.analyzeTool.setName(name)
self.analyzeTool.setModelFilename(self.model)
self.analyzeTool.setResultsDir(analyze_result_folder)
self.analyzeTool.setCoordinatesFileName(ik_file)
self.analyzeTool.setInitialTime(initial_time)
self.analyzeTool.setFinalTime(final_time)
self.analyzeTool.setLowpassCutoffFrequency(6)
analysis_set = self.analyzeTool.getAnalysisSet()
nAnalysis = analysis_set.getSize()
for k in range(nAnalysis - 1):
analysis = analysis_set.get(k)
analysis.setStartTime(initial_time)
analysis.setEndTime(final_time)
self.analyzeTool.run()
del self.analyzeTool
For i in range(100000):
...
...
do run_analyze()

Code: Select all


Thanks for your help in advance.
Mohsen

Re: Opensim memory leak during for loop

Posted: Sat Dec 05, 2020 11:45 am
by mitkof6
Hi Mohsen,

Maybe if you build the new version of OpenSim, where we fixed a memory leak ([1] and [2]) in the integrator, this might be resolved.

[1] https://github.com/opensim-org/opensim-core/issues/2865
[2] https://github.com/opensim-org/opensim-core/issues/2865

But this is not a guarantee. Maybe there is another memory leak in the analysis tool. I had similar issues in the past. What I did was to kill the Python process and start over from where the analysis stoped. It is not ideal.