S
Sasha
Hi all,
do you need to release java strings (or, for that matter, any java object)
you create in JNI code? I'm trying to find out why a particular piece of
code is crashing when I exit the program (long after the JNI code has
executed).
Of course, C-style strings need to be released. But do I need to tell Java
that I don't need to reference an object any more? Or will it just figure it
out and garbage collect an object automatically?
My code looks something like this:
/* call a logging method in the parent object */
void LogMessage(JNIEnv *environment, jobject instance, const char *message,
jint level)
{
/* convert string to java string */
jstring jsMessage = environment->NewStringUTF(message);
/* log da message */
jclass bridgeClass = environment->FindClass(BRIDGE_CLASS);
if (bridgeClass == 0)
return;
jmethodID log = environment->GetMethodID(bridgeClass, "log",
BRIDGE_LOG_SIG);
if (jmethodID == 0)
return;
jthrowable exc = environment->ExceptionOccurred();
if (exc) {
environment->ExceptionClear();
/* propagate exc */
environment->Throw(exc);
}
environment->CallVoidMethod(instance, log, jsMessage, level);
exc = environment->ExceptionOccurred();
if (exc) {
environment->ExceptionClear();
/* propagate exc */
environment->Throw(exc);
}
}
Any help would be greatly appreciated.
Regards,
Sasha.
do you need to release java strings (or, for that matter, any java object)
you create in JNI code? I'm trying to find out why a particular piece of
code is crashing when I exit the program (long after the JNI code has
executed).
Of course, C-style strings need to be released. But do I need to tell Java
that I don't need to reference an object any more? Or will it just figure it
out and garbage collect an object automatically?
My code looks something like this:
/* call a logging method in the parent object */
void LogMessage(JNIEnv *environment, jobject instance, const char *message,
jint level)
{
/* convert string to java string */
jstring jsMessage = environment->NewStringUTF(message);
/* log da message */
jclass bridgeClass = environment->FindClass(BRIDGE_CLASS);
if (bridgeClass == 0)
return;
jmethodID log = environment->GetMethodID(bridgeClass, "log",
BRIDGE_LOG_SIG);
if (jmethodID == 0)
return;
jthrowable exc = environment->ExceptionOccurred();
if (exc) {
environment->ExceptionClear();
/* propagate exc */
environment->Throw(exc);
}
environment->CallVoidMethod(instance, log, jsMessage, level);
exc = environment->ExceptionOccurred();
if (exc) {
environment->ExceptionClear();
/* propagate exc */
environment->Throw(exc);
}
}
Any help would be greatly appreciated.
Regards,
Sasha.