Usually the Dispose method is called from
a finally section in a try-finally block
as you can see in the following example:
try
{
/* Allocate a huge array */
MWNumericArray array = new MWNumericArray(1000,1000);
.
. (use the array)
.
}
finally
{
/* Explicitly dispose of the managed array and its */
/* native resources */
if (null != array)
{
array.Dispose();
}
}
The statement array.Dispose() frees the memory
allocated by both the managed wrapper and the native MATLAB® array.
The MWArray class provides two disposal methods: Dispose and
the static method DisposeArray. The DisposeArray method
is more general in that it disposes of either a single MWArray or
an array of arrays of type MWArray.