title: How to fix JNI crash on env->NewObject?
body: <p>I'm trying to use Clang via JNI (Clang C-API).
  One moment after few iteractions it just stop creating new objects and crashes:</p>
  
  <blockquote>
    <p>map method
     0 args:
    create Method instance 0x7fa26ba23c90 0x7fa26ba2a0c0 libclang: crash
    detected during indexing source file: {   'source_filename' :
    '/Users/asmirnov/Documents/dev/src/clang_jni/mac/test/TestFile.h'<br>
    'command_line_args' : ['-c', '-x', 'c++'],   'unsaved_files' : [],<br>
    'options' : 0, }</p>
  </blockquote>
  
  <p>The code is pretty straight-forward:</p>
  
  <pre><code>mapMethod(JNIEnv *env, const CXIdxDeclInfo *info) {
  
      debug("map method");
  
      int numArgs = clang_Cursor_getNumArguments(info-&gt;cursor);
      debug("  %i args:", numArgs);
  
      debug("create Method instance %p %p", MethodClass, MethodConstructor);
      jobject result = env-&gt;NewObject(MethodClass, MethodConstructor);
  
      debug("create Method  params instance");
  </code></pre>
  
  <p>Method class and constructor is found and registered as globals correctly (seems to be) and it works few iterations:</p>
  
  <pre><code>// method
      MethodClass = (jclass)env-&gt;NewGlobalRef(env-&gt;FindClass("name/antonsmirnov/clang/dto/index/Method"));
      debug(MethodClass != NULL ? "found MethodClass" : "not found MethodClass");
  
      MethodConstructor = env-&gt;GetMethodID(MethodClass, "&lt;init&gt;", "()V");
      debug(MethodConstructor != NULL ? "found MethodConstructor" : "not found MethodConstructor");
  </code></pre>
  
  <p>I've read some "jni tips and tricks" articles and tried to <code>env-&gt;DeleteLocalRef</code> and make local references count too big just to try, but no result:</p>
  
  <pre><code>// magic 
      jint ensureResult = env-&gt;EnsureLocalCapacity(1024);
      debug("ensure result %i", ensureResult);
  
      jint pushResult = env-&gt;PushLocalFrame(1024);
      debug("push result %i", pushResult);
  </code></pre>
  
  <p>Clang is hijacking exception so i can't see the real reason.
  The problem happens after few iterations as i said so it seems to be some limit exceeded problem or smth.</p>
  
  <p>What is wrong?</p>
  
  <p><strong>UPDATE</strong>: I've done some research and i found that if i delete some local vars before then i can get one iteration more and one object instance more. So it makes me feel that it's using 16 local vars indeed and ignore my <code>EnsureLocalCapacity</code> invocation. Where should it be done?</p>