Reputation: 2122
So thats the flow of JNI
JNI_onLoad - get JavaVM (get jclass for calling static methods)
Then need to call something from Java to C:
GetEnv() to get JNIEnv and AttachCurrentThread() to use it.
Call java method
Process java method returned value.
DetachCurrentThread() - free thread
Somethere in the end
DestroyJavaVM()
Well questions are:
Upvotes: 2
Views: 3671
Reputation: 3334
DestroyJavaVM() must be called when you no longer use the JVM (probably at the end of your program).
JNI_onUnload is called when the class is unloaded (because its class loader was deleted for example).
to free a Class null its references and delete its classloader.
JNI jarrays/jarrays elements, strings and jobjects are either allocated by the JVM or using a C buffer (that you manage); see #3 for the former case.
AttachCurrentThreadAsDaemon() tells the JVM that it should not wait for the thread to exit upon shutdown (helpful for daemons).
Good luck!
Upvotes: 3