title: will cache jclass in native code prevent the class been unloaded
body: <p>According to <a href="https://developer.android.com/training/articles/perf-jni.html" rel="nofollow noreferrer">https://developer.android.com/training/articles/perf-jni.html</a>:</p>
  
  <blockquote>
    <p>The class references, field IDs, and method IDs are guaranteed valid until the class is unloaded. Classes are only unloaded if all classes associated with a ClassLoader can be garbage collected</p>
  </blockquote>
  
  <p>if I keep a global reference of the class, will it guarantee the class never been unloaded?</p>
  
  <pre><code>static jclass g_classMyClass;
  
  jint JNI_OnLoad(JavaVM *pJVM, void *reserved)
  {
      JNIEnv *pEnv;
      if (pJVM-&gt;GetEnv((void**)&amp;pEnv, JNI_VERSION_1_6) != JNI_OK) {
          return -1;
      }
  
      jclass classMyClass = pEnv-&gt;FindClass("com/example/MyClass");
      g_classMyClass = (jclass)pEnv-&gt;NewGlobalRef(classMyClass);
  
      return JNI_VERSION_1_6;
  }
  </code></pre>