From: zhang on
Hi guys

When I use mxCreateDoubleMatrix to create a matrix in a mex file, need I release it using mxDestroyArray?

Actually, I have tried using mxDestroyArray function. The matlab give me a problem that release memory that is freed.

Thanks in advanced
From: James Tursa on
"zhang " <xiaoc10(a)gmail.com> wrote in message <i2tju3$no4$1(a)fred.mathworks.com>...
> Hi guys
>
> When I use mxCreateDoubleMatrix to create a matrix in a mex file, need I release it using mxDestroyArray?
>
> Actually, I have tried using mxDestroyArray function. The matlab give me a problem that release memory that is freed.
>
> Thanks in advanced

If you are returning the matrix as part of the plhs[ ] array, then do not destroy it. But if it is a temporary matrix you created that is not being used anymore or returned via the plhs[ ] array, then you should free it with the mxDestroyArray function. MATLAB is nice to you in this regards, however, in that if you do not destroy it MATLAB will automatically do so when the mex function returns to MATLAB. IMO, it is not good programming practice to rely on this since it creates a temporary memory leak in your routine that is not fixed up until the mex function returns to MATLAB.

Can you be more specific about the problems you are having?

James Tursa
From: Malcolm McLean on
"zhang " <xiaoc10(a)gmail.com> wrote in message <i2tju3$no4$1(a)fred.mathworks.com>...
>
> When I use mxCreateDoubleMatrix to create a matrix in a mex file, need I release it >using mxDestroyArray?
>
No. Matlab has an intelligent memory manager that free all memory allocated with mex calls (mxMalloc etc, but not plain malloc()), on exit from the function.

Only rarely will you want to destroy an array, which you would only do it it were very large and needed only for some intermediate calclualtion.
If you are returning the array to the user through prhs[], you may not destroy the array.
 | 
Pages: 1
Prev: Report Generator Style Sheet help
Next: warning