JNI ERROR(app bug):本地引用表溢出

时间:2015-02-12 09:23:20

标签: c++ android-ndk

我将代码编写为

jclass clazz = env -> FindClass("java/lang/System");
    jclass globalClass = reinterpret_cast<jclass>(env->NewGlobalRef(clazz));
    jmethodID methodId = env -> GetStaticMethodID(globalClass, "load", "(Ljava/lang/String;)V");
    jstring j_file = env -> NewStringUTF(filename.c_str());
    env -> CallStaticVoidMethod(globalClass, methodId, j_file);
    if(env -> ExceptionCheck())
    {
        env -> ExceptionDescribe();
        env -> ExceptionClear();
        LOG_E("Load library error!");
    }
    else
    {
        LOG_E("load library success");
    }
    env -> ReleaseStringUTFChars(j_file, filename.c_str());
    env -> DeleteGlobalRef(clazz);

运行时,它的错误为

A/art(4412): 
art/runtime/indirect_reference_table.cc:113] JNI ERROR (app bug): 
local reference table overflow (max=512)` `A/art(4412): 
art/runtime/indirect_reference_table.cc:113] local reference table dump: 
Last 10 entries (of 512):

我不知道为什么,你能帮助我吗?

2 个答案:

答案 0 :(得分:0)

ReleaseStringUTFChars()不会发布j_file。查看documentation

您需要致电DeleteLocalRef(j_env, j_file)

答案 1 :(得分:-1)

在jni中,我重写了System.nativeLoad的方法,当我调用System.load时,System.load调用nativeLoad,所以......