title: Use method 'NewGlobalRef' to reference a global reference
body: <p>I am writing an android jni application, and want to use many global references. <strong>Can I reference a global reference with 'NewGlobalRef'</strong>?</p>
  
  <p>I have tried the following and it works, but I don't know if this is allowed. I also don't know if 'NewGlobalRef' principle is whether the <strong>global reference points to a global reference</strong> or <strong>two global references point to an object</strong> (like shared_ptr)?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;jni.h&gt;
  
  class A {
  public:
      A(JNIEnv * env, jobject obj) : env(env)
      {
          globalRef = env-&gt;NewGlobalRef(obj);
          env-&gt;DeleteLocalRef(obj);
      }
      A(const A &amp; a) : env(a.env)
      {
          // a global reference points to a global reference ?
          // or two global references point to an object ?
          globalRef = env-&gt;NewGlobalRef(a.globalRef);
      }
      ~A()
      {
          env-&gt;DeleteGlobalRef(globalRef);
          globalRef = nullptr;
      }
  private:
      JNIEnv * env;
      jobject globalRef;
  };
  
  // main entry
  JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM * jvm, void * reserved)
  {
      JNIEnv *env;
      if (jvm-&gt;GetEnv((void**)&amp;env, JNI_VERSION_1_4) != JNI_OK)
          return JNI_ERR;
      A a1(env, env-&gt;NewStringUTF("somthing"));
      A a2(a1);
      a1.~A();
      // Can I continue to use 'a2' after 'a1' is destroyed ?
      return JNI_VERSION_1_4;
  }
  </code></pre>
  
  <p>I expect I can continue to use 'a2' after 'a1' is destroyed.</p>