Memory Leaks using MEX file
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
James Tursa
2013-4-9
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 个评论
James Tursa
2013-4-9
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.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!