title: memory allocated in native code between jni calls
body: <p>Can I allocate a memory block in one JNI function, and release one in another JNI function? </p>
  
  <p>I'm afraid, that jvm catchs call of malloc from native function, and release it when function finished; For example, is this code correct:</p>
  
  <pre><code>char * buffer; 
  JNIEXPORT jlong JNICALL Java_test_init(JNIEnv *env, jobject obj) {
     buffer = malloc(1000);
     return (jlong)buffer; //for check it
  }
  
  JNIEXPORT void JNICALL Java_test_use(JNIEnv *env, jobject obj) {
     // some code, that used buffer
  }
  
  JNIEXPORT void JNICALL Java_test_done(JNIEnv *env, jobject obj) {
     free(buffer);
  }
  </code></pre>
  
  <p>UPD: I read about direct buffer (NewDirectByteBuffer) and global refererences (NewGlobalRef) but i asked, can I allocate memory without use JNI API, just with call 'malloc'</p>