MATLAB BUILDER JA 2 User's Guide Page 71

  • Download
  • Add to my manuals
  • Print
  • Page
    / 292
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 70
Managing Native Resources
Managing Native Resources
When your code accesses Java classes created by MATLAB Builder for Java,
your program uses native resources, which e xist outside the control of the
Java Virtual Machine (JVM).
Specifically, each MWArray data conversion class is a wrapper class that
encapsulates a M ATLAB m xArray. The encapsulated MATLAB array
allocates resources from the native memory heap.
Note Because the Java wrapper is small and the mxArray is relatively large,
the J VM memory manager may not call the garbage collector before the
native memory becomes exhausted or badly fragmented. This means that
native arrays should be explicitly freed.
You can use any of the following techniques to free m e mory:
“Using Garbage Collection Provided by the JVM” on page 3-25
“Using the dispose Method” on page 3-26
“Overriding the O bject.Finalize Method” on page 3-27
Using Garbage Collection Provided by the JVM
When you create a new instance of a Java class, the JVM allocates and
initializes the ne w object. Wh en this object goes o u t of scope, or becomes
otherwise unreachable, it becomes eligible for garbage collection by the JVM.
The m e mory allocated by the object is eventually freed when the garbage
collector is run.
When you instantiate
MWArray classes, the encapsulated MATLAB also
allocates space for native resources, bu t these resources are not visible to the
JVM and are not eligible for garbage collection by the JVM. These resources
are not released by the class finalizer until the JVM determines that it is
appropriate to run the garbage collector.
The re sources allocated by
MWArray objects can be quite large and can quickly
exhaust your available memory. To avoid exhausting the n ative memory
3-25
Page view 70
1 2 ... 66 67 68 69 70 71 72 73 74 75 76 ... 291 292

Comments to this Manuals

No comments