MATLAB: Call mxDestroyArray() after mxCreateDoubleScalar()

MATLAB Compiler

Hi,
I understand if the following code is the standard way of initiating, using and destroying a mxArray in C++:
mxArray *mxData;
mxData = mxCreateDoubleArray(0.1);
mlfSomeFunction(mxData);
mxDestroyArray(mxData);
However, what if I do such:
mlfSomeFunction(mxCreateDoubleArray(0.1));
Do I need to call mxDestroyArray()? If yes, how? I actually tried it. It compiles and runs fine. But I would want to make sure there is no memory leaks…
Thanks
Bo

Best Answer

You do not need to call mxDestroyArray for temporary anonymous objects. Matlab is so kind to delete them automatically if the function is left.