How Do I free up a Fortran Mexed substructure (running out of memory-leaking memory)

1 次查看(过去 30 天)
I have a program inwhich matlab is calling a mexed Fortran 77 subroutine. Created in the mexed fortran file is a structure within structure for output. So I create these temporary structures that creates the main output structure.. So that all works fine......... Now its a matter of RELEASING these temporary subs structures because after the program gets called a few 1000 times, I get the low-memory notice, then soon matlab crashes and burns. I had the task manager showing me that the PF usuage does not drop back down after each call.
The temporary structures being created are using: tmpstruct = mxCreateStructMatrix(x,x,x,x)
I have tried at the end of the fortran file before it returns to matlab the following: mxfree(tmpstruct) and mxDestroyArray(tmpstruct) and the memory never never gets released until I shut down matlab or the memory leak shuts down matlab.
Any ideas ????

回答(1 个)

Philip Borghesani
Philip Borghesani 2014-8-29
编辑:Philip Borghesani 2014-8-29
Unless you are calling mexMakeArrayPersistent I suspect you have another leak than that one. Matlab will eventually clean up all mxArrays (actuality any call to mxCreate... or mxMalloc) allocated by a mex file. It is best practice to do this yourself with mxDestroyArray (NOT mxFree) for performance and cleanliness reasons but not necessary especially if your code calls mexError...
I would look for any code that uses Fortran dynamic memory directly. Reduce your code to the minimum that leaks and post it here if you have not found the leak.

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by