我是JNI的新手,在我测试的其中一部手机上,我收到ReferenceTable overflow
的错误。我知道这与不在本机代码中发布JNI / Java项目有关。
我认为我不需要发布任何内容,因为我使用给定的jfloatarray
,替换它的值,然后再次返回原始的JNI对象。我认为这会让JNI释放对象本身,因为它只是让它回来了。
JNI代码:
extern "C"
JNIEXPORT jfloatArray JNICALL Java_methodname(
JNIEnv *env, jobject thiz, jfloatArray data)
{
float* nativeValues = (float *)env->GetFloatArrayElements(data, 0);
doSomething(nativeValues);//overwrite the values with new values
return data;
}
JNI错误(Android 2.3):
11-28 15:00:58.069: W/dalvikvm(833): ReferenceTable overflow (max=1024)
11-28 15:00:58.069: W/dalvikvm(833): Last 10 entries in JNI pinned array reference table:
11-28 15:00:58.069: W/dalvikvm(833): 1014: 0x405f3750 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1015: 0x405f37b0 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1016: 0x405f3810 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1017: 0x405f3870 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1018: 0x405f38d0 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1019: 0x405f3930 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1020: 0x405f3990 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1021: 0x405f39f0 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1022: 0x405f3a50 cls=[F (20 bytes)
11-28 15:00:58.069: W/dalvikvm(833): 1023: 0x405f3ab0 cls=[F (20 bytes)
11-28 15:00:58.074: W/dalvikvm(833): JNI pinned array reference table summary (1024 entries):
11-28 15:00:58.074: W/dalvikvm(833): 1020 of [F 20B (1020 unique)
11-28 15:00:58.074: W/dalvikvm(833): 4 of [F 28B (4 unique)
11-28 15:00:58.074: W/dalvikvm(833): Memory held directly by tracked refs is 20512 bytes
11-28 15:00:58.074: E/dalvikvm(833): Failed adding to JNI pinned array ref table (1024 entries)
我该怎么办?将数据值复制到新的float*
并创建一个新的jfloatarray
?
答案 0 :(得分:0)
当您通过GetFloatArrayElements(..)
函数获取元素时,您需要释放数组元素,因为JVM将其标记为“在本机代码中使用”。
请致电ReleaseFloatArrayElements()
。
查看详细信息:
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp17440