Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB Builder NE   

Using Dispose to Explicitly Free Resources

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.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS