S
Sambucus
Hi group!
I am using C++ and java with JNI to get some text in a RICHEDIT to my
java program. I do so by accessing a C++ method every second. It all
works fine except that it leaks memory every call I make to the C++
method.
Can anyone please help me with this problem? I am not sure wether the
leakage is in the C++ or java code. But i guess it's on the C++ side
since I'm kind of newbee there.
Is there perhaps a way to release the memory allocated for a LPTSTR in
C++?
Please take a look at the code below, it is the method i call every
second from java. I belive it is the LPTSTR that is leaking, since it
leaks more when the string gets larger.
<---------------
LPTSTR output;
JNIEXPORT jstring JNICALL
Java_JNIHandler_getDealerOutput(JNIEnv *env, jobject obj){
size = SendMessage(
(HWND) textarea, // handle to destination window
WM_GETTEXTLENGTH, // message to send
(WPARAM) 0,
(LPARAM) 0 ) +1;
output = new TCHAR[size];
SendMessage(textarea,
WM_GETTEXT,
size,
(LPARAM)(void*)output);
return env->NewStringUTF(dealerStr);
}
------------------>
I have tried to release the memory allocated when the NewStringUTF is
made with the JNI.h method env -> ReleaseStringUTFChars(str,
dealerStr) to no avail.
I hae also tried to use a try/finally block and in the finally set:
output= NULL; delete output; but there is no difference.
Cheers
Andreas
I am using C++ and java with JNI to get some text in a RICHEDIT to my
java program. I do so by accessing a C++ method every second. It all
works fine except that it leaks memory every call I make to the C++
method.
Can anyone please help me with this problem? I am not sure wether the
leakage is in the C++ or java code. But i guess it's on the C++ side
since I'm kind of newbee there.
Is there perhaps a way to release the memory allocated for a LPTSTR in
C++?
Please take a look at the code below, it is the method i call every
second from java. I belive it is the LPTSTR that is leaking, since it
leaks more when the string gets larger.
<---------------
LPTSTR output;
JNIEXPORT jstring JNICALL
Java_JNIHandler_getDealerOutput(JNIEnv *env, jobject obj){
size = SendMessage(
(HWND) textarea, // handle to destination window
WM_GETTEXTLENGTH, // message to send
(WPARAM) 0,
(LPARAM) 0 ) +1;
output = new TCHAR[size];
SendMessage(textarea,
WM_GETTEXT,
size,
(LPARAM)(void*)output);
return env->NewStringUTF(dealerStr);
}
------------------>
I have tried to release the memory allocated when the NewStringUTF is
made with the JNI.h method env -> ReleaseStringUTFChars(str,
dealerStr) to no avail.
I hae also tried to use a try/finally block and in the finally set:
output= NULL; delete output; but there is no difference.
Cheers
Andreas