title: If JNI DeleteGlobalRef() is called, does the corresponding java object get garbage collected?
body: <p>What I mean is, if I create a global reference jobject in C++, and then pass that off to some Java code, and delete call DeleteGlobalRef(), is that underlying java object potentially garbage collected right away, so that any future Java code that is already refering to that object might come back with a NullPointerException?  Specifically, if I have some C++ code that does something like this simplified example:</p>
  
  <pre><code>static jobject myObjGlobalRef;
  static JNIEnv* env = /* call to create a JVM and get the JNI env */;
  jobject ReturnMyObj()
  {
      /* &lt;&lt;Code that defines class, constructorId, and param1 goes here&gt;&gt; */
  
      jobject localObj = env-&gt;NewObject(class, constructorId, param1);
      myObjGlobalRef = env-&gt;NewGlobalRef(localObj);
  }
  
  void DeleteMyObj()
  {
      env-&gt;DeleteGlobalRef(myObjGlobalRef);
  }
  
  myObjGlobalRef = ReturnMyObj();
  
  jobject otherExistingGlobalRef = /* Assume we get another global ref to another parent obj somewhere else */
  /*  ... other code here ... */
  // Invoke some method on some other pre-existing global reference that uses
  // myObjGlobalRef,  lets assume this method stores the object referenced by
  // myObjGlobalRef into a parent object referenced by otherExistingGlobalRef:
  env-&gt;CallVoidMethod(env, otherExistingGlobalRef, addASubObjectMethodId, myObjGlobalRef);
  
  DeleteMyObj();
  
  // Does the pointed to by myObjGlobalRef still exist here, assuming that
  // otherExistingGlobalRef now references it?
  </code></pre>
  
  <p>How does this work in JNI?  Is a "GlobalReference" on an object just a reference count to the object, so that if I free the GlobalReference jobject, it does not necessarily garbage collect the underlying java object until all references to it (such as the "parent" object otherExistingGlobalRef referencing it) are gone?</p>
  
  <p>If you can answer this and provide a link to some official Java/Sun/Oracle documentation backing up your answer, you earn bonus kudos :-).</p>