The documentation for MATLAB 7.6 (R2008a) has been updated to incorporate the relevant information. For previous product releases, read below for any possible workarounds:
Documentation on destroying structure arrays is not available in MATLAB 7.2 (R2006a). Here is additional information on destroying structure arrays in MATLAB:
If you create a structure matrix or array and use mxSetField or mxSetFieldByNumber to put another mxArray's data into the structure, it is not copied, rather the structure's field points to the other mxArray. When the structure is destroyed, it attempts to traverse down through itself and free all other data. Therefore, if the data array is destroyed and then the structure array is destroyed, the same memory is freed twice.
To workaround this issue, destroy the structure only as follows:
mxArray *myDataOne;
mxArray *myDataTwo;
mxArray *aStruct;
const char *fields[] = { "one", "two" };
myDataOne = mxCreateDoubleScalar(1.0);
myDataTwo = mxCreateDoubleScalar(2.0);
aStruct = mxCreateStructMatrix(1,1,2,fields);
mxSetField( aStruct, 0, "one", myDataOne );
mxSetField( aStruct, 0, "two", myDataTwo );
mxDestroyArray(aStruct);
Best Answer