Hi!
In my native method, I'm calling into Java. I am creating a byte array
from an existing byte[] in native code and I am setting this byte[] to
pair in a HashMap.
When trying to release, I get:
08-02 14:29:18.252: WARN/dalvikvm(4338): JNI:
unpinPrimitiveArray(0x40922120) failed to find entry (valid=1)
Why is that? Is my code leaking array reference? I am monitoring gc
output and memory consumption is stable....
The code (edited for brevity): (alternatively:
http://pastebin.com/4KeGu3LN)
LOGD("Size of image: %d", data->byteCount);
jbyteArray imageBuf = p_env->NewByteArray(data->byteCount);
p_env->SetByteArrayRegion(imageBuf, 0, data->byteCount, (jbyte*)data-
>buffer); (data->buffer contains byte[])
jobject imageHashmap = jni_helpers_HashMap_create(p_env); // creates
HashMap using NewObject
jstring key = p_env->NewStringUTF("data");
jni_helpers_HashMap_put(p_env, imageHashmap, key, imageBuf); // call
put method on a HashMap instance
p_env->DeleteLocalRef(key);
key = p_env->NewStringUTF("width");
jobject intVal = jni_helpers_create_Integer(p_env, data->width);
jni_helpers_HashMap_put(p_env, imageHashmap, key, intVal);
p_env->DeleteLocalRef(key);
p_env->DeleteLocalRef(intVal);
key = p_env->NewStringUTF("height");
intVal = jni_helpers_create_Integer(p_env, data->height);
jni_helpers_HashMap_put(p_env, imageHashmap, key, intVal);
p_env->DeleteLocalRef(intVal);
p_env->DeleteLocalRef(key);
p_env->CallVoidMethod(g_callbackTarget, g_callbackMethod, EVENT_ID,
(jobject)imageHashmap);
LOGD("Cleaning up resources...");
p_env->ReleaseByteArrayElements(imageBuf, (jbyte*)data->buffer,
JNI_ABORT); // <!-- this is where I get the message
p_env->DeleteLocalRef(imageBuf);
p_env->DeleteLocalRef(imageHashmap);