mxDestroyArray is used to free dynamic memory allocated by mxCreate. This applies to any time you create an mxArray, such as with most of the mxArray API functions (mxCreateDoubleMatrix, mxCreateCellMatrix, etc). This also applies to engGetVariable, because engGetVariable returns a pointer to a newly allocated mxArray. mxDestroyArray should be called to free that dynamic memory when finished.
mxFree is used to free dynamic memory allocated by mxCalloc, mxMalloc, or mxRealloc (similar to their malloc counterpart, except they use the MATLAB memory manager). Calls to mxFree are less common.
Best Answer