Do I need to call ReleaseIntArrayElements on an array created with NewIntArray?

java, java-native-interface

Solution

You don't need to do anything with it. It is a local reference and it will be cleaned up when your JNI method exits. As Edward Thompson hints above, `ReleaseIntArrayElements()` is the converse of `GetIntArrayElements().` It has no other function.

Problem

I have a native method that does some work on a bitmap. Inside the method I grab the image data via a method call that writes the data to a `jintArray` parameter that I've created with `NewIntArray`: `jintArray pixels = env->NewIntArray(width * height);` I don't need to return this array back to the calling Java code - it's only for processing while in this method. Do I need to call `ReleaseIntArrayElements` on `pixels`? If so, what do I pass for the `elems` parameter, since I don't need to copy it back to a Java array? `void (JNICALL *ReleaseIntArrayElements) (JNIEnv *env, jintArray array, jint *elems, jint mode);`

Original source