Source
Matlab Help:
Memory Management Compatibility Issues
Syndrome
The matlab engine properly opens and closes at the first time. But at the second attempt of starting matlab engine the error message pops up:
Forced Assertion: "Corrupted memory block found"
Cause
- mxDestroyArray was called on a mxArray whose data was not assigned by matlab API
mxArray *temp = mxCreateDoubleMatrix(1,5,mxREAL);
double data[5] = {1,2,3,4,5};
...
memcpy(mxGetPr(temp), data, 5*sizeof(double));
...
mxDestroyArray(temp); // <-- INCORRECT. Do NOT call mxDestroyArray on temp
Solution
- Do NOT call mxDestroyArray on such mxArray's