NewObjectArray--java.lang.OutOfMemoryError: Java heap space
Hi,
I have been working on an application where I need to get data from a C++ object. Thus far I have had java call into the native code to extract it, but found that the design would be better to have C++ send the data to java when it deems appropriate. My problem is that now that I am having C++ call into java, the application eventually starts giving the following error: Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Just before I start seeing this error the following code starts returning NULL, which only happens "if the system is out of memory" according to JNI specs.
array = env->NewObjectArray(max, stringCls, NULL);
if(array == NULL){
// error handling...
}
I don't understand the deep workings of java and JNI, but my only guess is that for some reason when I call from C++ into java, the garbage collector is unable to destroy all of the previous objectarrays. The changes I made are I now pass the array from JNI into java instead of returning it and I connect to the JVM and JNIEnv* as follows:
JNIEnv* env;
jvm->AttachCurrentThread(reinterpret_cast<void**>(&env), NULL);
Where jvm is a global that is set in a previously called function.
As far as I understand, this is the correct way to connect to the jvm.
If anyone has any ideas I would greatly appreciate it.
Mark
Message was edited by:
mebbert
null

