IBM User Guide for Java V7 on Windows > IBM SDK for Java > The Java Native Interface (JNI) > Copying and pinning



Using the mode flag

When you call Release<Type>ArrayElements, the last parameter is a mode flag. The mode flag is used to avoid unnecessary copying to the Javaâ„¢ heap when working with a copied array. The mode flag is ignored if you are working with an array that has been pinned.

You must call Release<Type> once for every Get<Type> call, regardless of the value of the isCopy parameter. This step is necessary because calling Release<Type> deletes JNI local references that might otherwise prevent garbage collection.

The possible settings of the mode flag are:

0

Update the data on the Java heap. Free the space used by the copy.

JNI_COMMIT

Update the data on the Java heap. Do not free the space used by the copy.

JNI_ABORT

Do not update the data on the Java heap. Free the space used by the copy.

The ‘0' mode flag is the safest choice for the Release<Type> call. Whether the copy of the data was changed or not, the heap is updated with the copy, and there are no leaks.

To avoid having to copy back an unchanged copy, use the JNI_ABORT mode value. If you alter the returned array, check the isCopy flag before using the JNI_ABORT mode value to "roll back" changes. This step is necessary because a pinning JVM leaves the heap in a different state than a copying JVM.


Parent: Copying and pinning








Error 404 - Not Found

Error 404 - Not Found

The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.