According to The Official Documentation Says:
Local references are valid for the duration of a native method call, and are automatically freed after the native method returns
Imaging a case, We have a native framework a.so
And we load it.
static JavaVM * g_cachedJVM;
CJNIEXPORT jint JNICALL JNI_OnLoad(JavaVM * jvm, void * /*reserved*/) {
g_cachedJVM = jvm;
return JNI_VERSION_1_6;
}
And we call a native method implement by a.so, we start a c++ timer in this method.
CJNIEXPORT jobject JNICALL Java_A_Custom_Method(JNIEnv* jniEnv, jobject /*this*/) {
startTimerInCurrentTheadWithoutBlockCurrentThread(Seconds(1),[](){
//invoke method every 1 second
cppMethod();
});
}
void cppMethod() {
//Create some jni local reference use g_cachedJVM
// what is the life cycle of the local reference?
}
Question: what is the life cycle of the local reference in the cpp method