Matlab Scripting: "RRATool" Memory Leak?

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Stephen Riutta
Posts: 20
Joined: Wed May 23, 2012 3:55 pm

Matlab Scripting: "RRATool" Memory Leak?

Post by Stephen Riutta » Sat Apr 06, 2013 4:49 pm

Hello,

I'm able to use Matlab scripting (on both 2012a and 2013a) to successfully run RRA on a model. However, each time I execute rraTool.run(); in Matlab, the physical memory usage of Matlab increases. I'm using this command in a loop, and after about 20 iterations, I run out of physical memory and the program freezes. My physical memory monitor shows a uniform, incremental increase in memory usage.

I've tried a variety of memory clearing techniques (clear java, clear all, clear classes, etc) but have not been able to stop the memory usage from increasing during each iteration. Closing Matlab frees the memory. I've heard that using handles on Java objects may prevent memory leaks in Matlab, but that didn't seem to work for me. I'm not sure if I was implementing the handles correctly however.

I was interested in knowing if there is a way to prevent the memory usage from increasing with each iteration.

Thanks,

Stephen

User avatar
Ayman Habib
Posts: 2238
Joined: Fri Apr 01, 2005 12:24 pm

Re: Matlab Scripting: "RRATool" Memory Leak?

Post by Ayman Habib » Mon Apr 08, 2013 9:19 am

Hi Stephen,

We found some memory leaks and fixed them. The fixes will be in the next release but it's hard to tell if that's what you're running into or not since Java uses garbage collection which is easier on the client side but opens the door for other problems. For example, the garbage collector will not release resources if you're holding a reference to them even if you do not intend to use these references in the future. You maybe able to get away with writing your configuration to a file and use the rra executable (instead of running inside Matlab). It's a little more cumbersome but will allow you to get around any memory issues internal to RRA since resources are released on exit.

Hope this helps,
-Ayman

User avatar
Stephen Riutta
Posts: 20
Joined: Wed May 23, 2012 3:55 pm

Re: Matlab Scripting: "RRATool" Memory Leak?

Post by Stephen Riutta » Tue Apr 09, 2013 9:40 am

Hi Ayman,

Running the RRA executable in my loop prevents the memory usage increase. Thanks for the tip with that.

I'm planning on continuing to use the executables with my loops, but just to follow up with the previous issue: My memory usage was increasing about 30mb for each iteration. You mentioned that a memory leak issue was corrected, but the 30mb increase seems to be too large to be caused by that. I did try setting the model and rraTool objects to null (in Matlab I used [], and NaN) to remove the references so they could be cleaned by the garbage collector, but that didn't change the results. I'll continue trying different approaches with this to see if I can get it figured out.

Thanks again!

Stephen

User avatar
Xiangjie Meng
Posts: 15
Joined: Wed Sep 05, 2012 8:09 pm

Re: Matlab Scripting: "RRATool" Memory Leak?

Post by Xiangjie Meng » Thu May 08, 2014 9:26 am

Hi,

I am running the Static Optimization and also meet this problem. Could you please tell whether you have suggestions how to deal with this problem?

Thanks,
Jack

POST REPLY