User`s manual
1 Calling C and Fortran Programs from MATLAB
1-38
We highly recommend that you fix code in your MEX-files that produces any of
the warnings discussed in the following sections. For additional information,
see “Memory Management” on page 2-38 in Creating C Language MEX-Files.
Note Currently, the following warnings are enabled by default for backwards
compatibility reasons. In future releases of MATLAB, the warnings will be
disabled by default. The programmer will be responsible for enabling these
warnings during the MEX-file development cycle.
Improperly Destroying an mxArray
You cannot use mxFree to destroy an mxArray.
Warning
Warning: You are attempting to call mxFree on a <class-id> array.
The destructor for mxArrays is mxDestroyArray; please call this
instead. MATLAB will attempt to fix the problem and continue, but
this will result in memory faults in future releases.
Example That Causes Warning
In the following example, mxFree does not destroy the array object. This
operation frees the structure header associated with the array, but MATLAB
will still operate as if the array object needs to be destroyed. Thus MATLAB
will try to destroy the array object, and in the process, attempt to free its
structure header again.
mxArray *temp = mxCreateDoubleMatrix(1,1,mxREAL);
...
mxFree(temp); /* INCORRECT */