Do I need to call ReleaseIntArrayElements on an ar

2020-08-13 08:09发布

问题:

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);

回答1:

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.



回答2:

You have to release only reference:

jintArray pixels = env->NewIntArray(width * height);
...
env->DeleteLocalRef(pixels)