MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 73

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 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
Przeglądanie stron 72
1 2 ... 68 69 70 71 72 73 74 75 76 77 78 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag