The stackoverflow.com/questions/5859673 states that the ReleaseStringUTFChars()
must be called regardless the string was copied or not. So what is the parameter jboolean *isCopy
in the GetStringUTFChars()
good for?
Can I release the C string when the original jstring is out of scope? For example in this pseudo code:
static const char *cstr;
JNIEXPORT void JNICALL Java_com_Run(JNIEnv *e, jobject obj, jstring s) {
cstr = (*e)->GetStringUTFChars(e, s, 0);
}
void cfunc() {
// Can I use and release the cstr here? How?
}
According to documentation I have to get a reference via NewGlobalRef()
and release it later if I want to use java object after the JNI call finish. Is this rule valid for strings retrieved via GetStringUTFChars()
?