I have a problem with using mxDestroyArray. When I add it to my code, MATLAB crashes. Shouldn't I destroy any mxArray that I declared in my code just to avoid memory leak? Shouldn't each mxArray *myArr correspond to a mxDestroyArray(myArr) when the array is no longer needed?
You should only call mxDestroyArray on locally created mxArrays that are not being returned in plhs. Are you deleting mxArrays that are present in either prhs or plhs?
Does your mxArray happen to contain a Java object? I recently discovered the hard way that calling mxDestroyArray() on an mxArray that contains a Java object will cause a crash, even if you otherwise should call mxDestroyArray().
If you clear the pointer to the Java object before calling mxDestroyArray(), then it doesn't seem to crash, although I don't know if there are other ramifications.
mxSetData(myArr, NULL); mxDestroyArray(myArr);
Play games and win prizes!Learn more