Saturday, April 20, 2013

jni jnienv DeleteWeakGlobalRef example c c++ java


DeleteWeakGlobalRef

void DeleteWeakGlobalRef(JNIEnv *env, jweak obj);
Delete the VM resources needed for the given weak global reference.
LINKAGE:
Index 227 in the JNIEnv interface function table.
SINCE:
JDK/JRE 1.2
Example - DeleteWeakGlobalRef
JNIEXPORT void JNICALL
 Java_mypkg_MyCls_f(JNIEnv *env, jobject self)
 {
     static jclass myCls2 = NULL;
     if (myCls2 == NULL) {
         jclass myCls2Local =
             (*env)->FindClass(env, "mypkg/MyCls2");
         if (myCls2Local == NULL) {
             return; /* can't find class */
         }
         myCls2 = NewWeakGlobalRef(env, myCls2Local);
         if (myCls2 == NULL) {
             return; /* out of memory */
         }
     }
     ... /* use myCls2 */
 
 // After processing is done.
 DeleteWeakGlobalRef(env, myCls2Local);
}