根据此线程,由于 native 代码中的泄漏,我不断收到此错误:
ReferenceTable overflow (max=512) JNI
然而,在我看来,AttachCurrentThread 泄漏了。我试过这段代码,它泄漏了
// this code LEAKS!
// C++:
void Engine::UpdateCamera(float x, float y, float z) {
JNIEnv *jni;
app_->activity->vm->AttachCurrentThread(&jni, NULL);
//Do nothing
app_->activity->vm->DetachCurrentThread();
return;
}
// Java
public void updateCamera(final float x, final float y, final float z) {
if (_label2 == null)
return;
StackTraceElement trace = new Exception().getStackTrace()[0];
Log.e(APP_TAG, "Called:" +
trace.getClassName() + "->" + trace.getMethodName() + ":" + trace.getLineNumber());
}
然后我简单地注释掉所有内容,程序停止泄漏并永远运行:(
// this code never leaks, but it does not do anything either
void Engine::UpdateCamera(float x, float y, float z) {
JNIEnv *jni;
//app_->activity->vm->AttachCurrentThread(&jni, NULL);
//app_->activity->vm->DetachCurrentThread();
return;
}
有没有人遇到过 AttachCurrentThread 的泄漏问题?
谢谢你。
最佳答案
您是否已连接到调试器?如果是这样,断开连接,您可能会发现弱引用表返回到一个合理的值。
我有同样的问题;如果我使用调试器运行,就会发生这种情况。
关于android-ndk - "JNI ERROR (app bug): weak global reference table overflow"为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40028626/