1

我正在用 C++ 实现一个回调函数,但我面临一些泄漏问题。

数组创建的实现:

jshortArray convertShortArrayToJNI(JNIEnv* env, short* arr, size_t count) {
  jshortArray retval = env->NewShortArray(count);
  env->SetShortArrayRegion(retval,0,count,arr);
  return retval;
}

这里回调调用:

short* audio_frame;
int size;
jobject* callbackObject;
jshortArray array = convertShortArrayToJNI(jenv, audio_frame, size);
LOGI("array %d", array);
jenv->CallVoidMethod(*callbackObject, callbackMI, array);
LOGI("callback called!");
jenv->ReleaseShortArrayElements(array, audio_frame, 0);

一些电话后,它显示了以下错误:

12-03 11:12:38.425: W/dalvikvm(894): ReferenceTable overflow (max=512)
12-03 11:12:38.425: W/dalvikvm(894): Last 10 entries in JNI local reference table:
12-03 11:12:38.425: W/dalvikvm(894):   502: 0x44f879b0 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   503: 0x44f87a98 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   504: 0x44f87b80 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   505: 0x44f87c68 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   506: 0x44f87d50 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   507: 0x44f87e38 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   508: 0x44f87f20 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   509: 0x44f88008 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   510: 0x44f880f0 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894):   511: 0x44f881d8 cls=[S (100 bytes)
12-03 11:12:38.435: W/dalvikvm(894): JNI local reference table summary (512 entries):
12-03 11:12:38.435: W/dalvikvm(894):     1 of Ljava/lang/Class; 164B
12-03 11:12:38.435: W/dalvikvm(894):   511 of [S 100B (511 unique)
12-03 11:12:38.435: W/dalvikvm(894): Memory held directly by tracked refs is 51264 bytes

怎么了?

4

1 回答 1

7

这就是答案:ReferenceTable overflow (max=512) JNI

打电话jenv->DeleteLocalRef(array);解决我的问题!

于 2012-12-03T14:12:37.033 回答