Using Dispose to Explicitly Free Resources
Note
As of R2009b, native memory management for mxArray is
automatically handled by .NET's CLR memory manager. There is no longer
a reason to manually disable native memory management when working
with mxArray. Calls to disable memory management
will result in a null operation. |
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.
 | Creating an Instance of a Class | | Improving Data Access Using the MCR User Data Interface and MATLAB Builder NE |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit