[英]Android : JNI ERROR (app bug): local reference table overflow (max=512)
I have an android app which has native code. 我有一个Android应用程序,它有本机代码。 The native code needs to get a particular value from java code;
本机代码需要从java代码中获取特定值; this value updates regularly, so I need to get it when I need to use it.
这个值会定期更新,所以我需要在需要时使用它。 I am using JNI to make the call from native code to Java code.
我正在使用JNI来进行从本机代码到Java代码的调用。
std::string val;
JNIEnv* env = JSC::Bindings::getJNIEnv();
jclass bridgeClass = env->FindClass("com.mypackage.MyClass");
jmethodID method = env->GetStaticMethodID(bridgeClass, "getVal", "()Ljava/lang/String;");
val = jstringToStdString(env, static_cast<jstring>(env->CallStaticObjectMethod(bridgeClass, method)));
env->DeleteLocalRef(bridgeClass);
I make this call very often (almost 100 times a minute), and I am facing the following exception: 我经常拨打这个电话(几乎每分钟100次),我面临以下异常:
E/dalvikvm( 1063): JNI ERROR (app bug): local reference table overflow (max=512)
W/dalvikvm( 1063): JNI local reference table (0xcc8590) dump:
W/dalvikvm( 1063): Last 10 entries (of 512):
W/dalvikvm( 1063): 511: 0x413c7e70 java.lang.String "ABC"
W/dalvikvm( 1063): 510: 0x40a39470 java.lang.Class<android.util.Log>
W/dalvikvm( 1063): 509: 0x413c8558 java.lang.String "9287391238192... (24 chars)
W/dalvikvm( 1063): 508: 0x413c8558 java.lang.String "8298731897198... (24 chars)
W/dalvikvm( 1063): 507: 0x413c8558 java.lang.String "1983918729387... (24 chars)
W/dalvikvm( 1063): 506: 0x413c8558 java.lang.String "9283719732827... (24 chars)
W/dalvikvm( 1063): 505: 0x413c8558 java.lang.String "1231219897173... (24 chars)
W/dalvikvm( 1063): 504: 0x413c8558 java.lang.String "8237330127537... (24 chars)
W/dalvikvm( 1063): 503: 0x413c8558 java.lang.String "1293657681298... (24 chars)
W/dalvikvm( 1063): 502: 0x413c8558 java.lang.String "1298753090172... (24 chars)
W/dalvikvm( 1063): Summary:
W/dalvikvm( 1063): 2 of java.lang.Class (2 unique instances)
W/dalvikvm( 1063): 510 of java.lang.String (2 unique instances)
E/dalvikvm( 1063): Failed adding to JNI local ref table (has 512 entries)
All the similar questions online have the common answer that more resources need to be freed. 网上所有类似的问题都有共同的答案,即需要释放更多的资源。 Can anyone tell what other resources can I free in this case?
在这种情况下,谁能说出我可以免费获得的其他资源?
Thanks. 谢谢。
You need to delete the local ref to the value returned by 您需要删除本地引用返回的值
env->CallStaticObjectMethod(bridgeClass, method)
as follows: 如下:
jobject returnValue = env->CallStaticObjectMethod(bridgeClass, method);
// ...
env->DeleteLocalRef(returnValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.