MATLAB BUILDER JA 2 Guía de usuario Pagina 73

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 292
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 72
Managing Native Resources
The MWArray class prov ides two disposal methods: dispose and
disposeArray.ThedisposeArray method is more general in that it disposes
of either a single
MWArray or an array of arrays of type MWArray.
Code Fragment: Use try-finally to Ensure Resources A re Freed
Typically, the b est way to call the dispose method is from a finally clause
in a
try-finally block. This technique ensures that all native resources
are freed before exiting the method, even if an exception is thrown at some
point before the cleanup code.
Code Fragment: Using dispo se in a finally C la u se .
This example shows the use of dispose in a finally clause:
/* Allocate a huge array */
try
{
int[] dims = {1000, 1000};
MWNumericArray a = MWNumericArray.newInstance(dims,
MWClassID.DOUBLE, MWComplexity.REAL);
.
. (use the array)
.
}
/* Dispose of native resources */
finally
{
a.dispose();
/* Make it eligible for garbage collection */
a = null;
}
Overriding the Object.Finalize Method
You can also override the Object.Finalize method to help clean up native
resources just before garbage collection of the managed object. Refer to your
Java language reference documentation for detailed information on how to
override this method.
3-27
Vista de pagina 72
1 2 ... 68 69 70 71 72 73 74 75 76 77 78 ... 291 292

Comentarios a estos manuales

Sin comentarios