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);
Each method that can be called via JNI has a reflection metadata object. The address of this object is used as the method's jmethodID .
It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++). JNI is vendor-neutral, has support for loading code from dynamic shared libraries, and while cumbersome at times is reasonably efficient.
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.
You have to release only reference:
jintArray pixels = env->NewIntArray(width * height);
...
env->DeleteLocalRef(pixels)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With