Jni table overflow even after deleteLocalRef

When I run the code, I get the error "Failed to add 512 entries to the local JNI link table"

This is my code:

jstring pJNIData = pJNIEnv->NewStringUTF ( variables[0].GetStringValue() );

pJNIEnv->CallStaticVoidMethod ( pJNIActivityClass, pJNIMethodIDStartTime, pJNIData ) ;

pJNIEnv->DeleteLocalRef(pJNIData);

I read a few suggestions, but none of them work! Despite DeleteLocalRef, it does not work. The function is used in the profiler, which literally calls all the functions ...

+5
source share
2 answers

I saw this when the JNI method was called Java code (in my case, the method was not static). As far as I understand, unused local links are not automatically deleted when calling the Java method from the JNI (I mean, until the top-level JNI function returns).

IIRC , ; , . , , .

// in a function that calls a Java method from JNI
jbyteArray srcArray = env->NewByteArray(len);
jclass cls = env->FindClass("com/something/MyClass");
jmethodID mid = env->GetMethodID(cls, "mymethod", "([BI)[B");
jbyteArray resArray = (jbyteArray)env->CallObjectMethod(obj, mid, srcArray, XXXX);

...
env->DeleteLocalRef(cls);
env->DeleteLocalRef(resArray);
env->DeleteLocalRef(srcArray);
// no need to do anything with mid

, -, .

: http://www.netmite.com/android/mydroid/dalvik/docs/jni-tips.html#local_vs_global_references ( Dalvik VM docs dalvik/docs/jni-tips.html " " )

, JNI, " ". , . native, . , jclass jarray. [...] : - 32- , , NewGlobalRef. , , GetStringUTFChars GetByteArrayElements, .

+2

, , - . , !

, NDK, Java- apk, . , , , .

++ find getmethodid constuctor HashMap , HashMap. HashMap ++, jni-. . HashMap Java, , , . Java , DeleteLocalRef HashMap. , .

, , , 512 ( ), , 10 localref HashMaps. , GC , ndk. DeleteLocalRef .

: , HashMap jni- java, , , . , java, HashMap, , :)

0

All Articles