Reputation: 16015
I am a bit of a newbie with JNI, and on one of the phones I tested I get errors about ReferenceTable overflow
. I understand that this has to do with not releasing JNI/Java items in the native code.
I thought I did not need to release anything, because I use the given jfloatarray
, replace it's values and then return the original JNI object again. I assumed this would make JNI free the object itself,since it just gets it back.
JNI Code:
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 Error (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)
What should I do? Copy the data values to a new float*
and create a new jfloatarray
with that?
Upvotes: 1
Views: 1656
Reputation: 746
You need to release array elements due to JVM marks it as "used in native code" when you get elements by GetFloatArrayElements(..)
function.
Call ReleaseFloatArrayElements()
for that.
Check details there:
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp17440
Upvotes: 2