Memory Leaks using MEX file

11 Ansichten (letzte 30 Tage)
Zhangxian
Zhangxian am 9 Apr. 2013
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

Antworten (1)

James Tursa
James Tursa am 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 Kommentare
James Tursa
James Tursa am 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.
Zhangxian
Zhangxian am 10 Apr. 2013
I just replace all my mex functions with the original m file. The memory leak still exsits. Perhaps I should change my m file first. I use windows resource monitor to check matlab memory usage. The commit memory keeps increasing in each simulation step. My physical memory is 12GB, virtual memory is close to this size. But the commit memory goes above 28GB sometimes.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by