Android : JNI ERROR (app bug): local reference table overflow (max=512)(Android : JNI ERROR (app bug): local reference table overflow (max=512))
问题描述
I have an android app which has native code. The native code needs to get a particular value from java code; 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.
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:
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);
这篇关于Android : JNI ERROR (app bug): local reference table overflow (max=512)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android : JNI ERROR (app bug): local reference table overflow (max=512)
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01