Memory Leaks using MEX file
11 views (last 30 days)
Show older comments
Hello, I am running a matlab simulation which calls a MEX file for thousands of times in each simulation step. I use the "memory" command and find the memory usage of matlab is increased by 300 MB per step. This amount of memory is not used by workspace and it seems that it disappears on my computer. I have to quit matlab to release it.
I suppose this problem is called memory leak and has been discussed a lot. I am not a Java or C/C++ expert, are there any methods that I can reallocate or free the leaked memory after each simulation step?
Thanks a lot
Dan
0 Comments
Answers (1)
James Tursa
on 9 Apr 2013
If your mex file has a bug in it that is leaking memory, then the only thing you can do is get your hands on the source code, fix the bug, and recompile it. Once the memory is leaked (and I mean really leaked, not just temporarily leaked that gets recovered with garbage collection) there is nothing you can do to recover it short of quitting MATLAB and starting over.
3 Comments
James Tursa
on 9 Apr 2013
I am aware of emlmex but I don't know the details of how it creates the mex routine. You might consider looking at the optional inputs for the emlmex command ... maybe you can force it to do something slightly different that doesn't leak memory.
See Also
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!