I am having an issue with a JNI program randomly running out of memory.
This is a 32 bit java program which reads a file, does some image processing, typically using
My own approach to this problem is simply to call System.gc()
, but from inside the native code:
#include
// ...
int my_native_function(JNIEnv* env, jobject obj) {
jclass systemClass = nullptr;
jmethodID systemGCMethod = nullptr;
// ...
// Take out the trash.
systemClass = env->FindClass("java/lang/System");
systemGCMethod = env->GetStaticMethodID(systemClass, "gc", "()V");
env->CallStaticVoidMethod(systemClass, systemGCMethod);
}
I hope this works for you, too.