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

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 日

1 投票

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.

1 件のコメント

Rick
Rick 2014 年 8 月 29 日
Thank you Philip............. I will do that.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFortran with MATLAB についてさらに検索

質問済み:

2014 年 8 月 29 日

コメント済み:

2014 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by