zingo
asked on
NewStringUTF gives memory leak?
I have a thread running in native code which needs to call a static Java method with a jstring parameter.
Code:
jstring jstr;
char szTxt[MAX_DEBUG_OUT_LEN];
jclass cls;
jmethodID mid;
// Init code cut away here...
jstr = tmp_env->NewStringUTF(szTx t);
tmp_env->CallStaticVoidMet hod( cls, mid, jstr );
The problem I got is that the NewStringUTF seems to allocate memory, and I don't know how to deallocate it. The JVM doesn't seem to take care of it, "delete" does not work, and ReleaseStringUTFChars does not work either (they crash the app ).
How do I get rid of the memory?
Code:
jstring jstr;
char szTxt[MAX_DEBUG_OUT_LEN];
jclass cls;
jmethodID mid;
// Init code cut away here...
jstr = tmp_env->NewStringUTF(szTx
tmp_env->CallStaticVoidMet
The problem I got is that the NewStringUTF seems to allocate memory, and I don't know how to deallocate it. The JVM doesn't seem to take care of it, "delete" does not work, and ReleaseStringUTFChars does not work either (they crash the app ).
How do I get rid of the memory?
ASKER
The platform is Windows and I am using Visual J++.
I think taht from that site the code to free jstring is
const char *str = (*env)->GetStringUTFChars( env, Your_jstring, 0);
(*env)->ReleaseStringUTFCh ars(env, Your_jstring, str);
please let me know if this helps you out.
const char *str = (*env)->GetStringUTFChars(
(*env)->ReleaseStringUTFCh
please let me know if this helps you out.
ASKER
nope, it still leaks like a bottom-less bucket...
According to the documentation and examples from Sun, ReleaseStringUTFChars is used together with GetStringUTFChars. I've never seen it used with NewStringUTF.
According to the documentation and examples from Sun, ReleaseStringUTFChars is used together with GetStringUTFChars. I've never seen it used with NewStringUTF.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks ChristerH, you saved my day!
Oops ,and a thanks from me too, what we did was we had no need to track these as our .exe used to call Java object and go off.
I will bookmark this question.As they say u never stop learning.
:~)
I will bookmark this question.As they say u never stop learning.
:~)
http://sourceware.cygnus.com/ml/cygwin/1998-10/msg00615.html
>>>(they crash the app )
What platform Windows /Unixes?