Memory Leaks using MEX file

조회 수: 1 (최근 30일)
Zhangxian
Zhangxian 2013년 4월 9일
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

답변 (1개)

James Tursa
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
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.
Zhangxian
Zhangxian 2013년 4월 10일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by