title: Return a big object array from JNI?
body: <p>According to the <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#EnsureLocalCapacity" rel="nofollow">doc</a> </p>
  
  <blockquote>
    <p>jint EnsureLocalCapacity(JNIEnv *env, jint capacity);</p>
    
    <p>Ensures that at least a given number of local references can be
    created in the current thread. Returns 0 on success; otherwise returns
    a negative number and throws an OutOfMemoryError.</p>
    
    <p>Before it enters a native method, the VM automatically ensures that at
    least 16 local references can be created.</p>
    
    <p>For backward compatibility, the VM allocates local references beyond
    the ensured capacity. (As a debugging support, the VM may give the
    user warnings that too many local references are being created. In the
    JDK, the programmer can supply the -verbose:jni command line option to
    turn on these messages.) The VM calls FatalError if no more local
    references can be created beyond the ensured capacity.</p>
  </blockquote>
  
  <p>It seems there is some limitation for the number of Local Reference can be created.</p>
  
  <p>And I have following code to return a big object array, which leads to a lot of Local Reference creation.  Does that mean this would reach the limitation easily?  -- the doc says 16 by default.</p>
  
  <pre><code>extern "C" JNIEXPORT
  jobjectArray JNICALL Java_MessageQueueInterop_receive(JNIEnv * env, jobject this_obj, jclass cls)
  {
      int count = 99999;
      jobjectArray ret = env-&gt;NewObjectArray( count, cls, NULL);
      if( ret ){
          for( int i = 0; i &lt; count; i++ ) {
              jobject obj = env-&gt;NewObject( cls, constructor);
              if( obj ){
              env-&gt;SetIntField( obj, fieldID1, 2);
  
              jstring str = env-&gt;NewStringUTF("XXX");
              if( str )
                  env-&gt;SetObjectField( obj, fieldID2, str);
  
              env-&gt;SetObjectArrayElement( ret, i, obj);
              }
          }
      }
      return ret;
  }
  </code></pre>
  
  <p>How to extend the limitation?</p>