本文介绍了如何释放是从本地code回Java发送的jstring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的原生程序:
void sendMessage(const char* text)
{
JNIEnv* env;
if(!_jvm)
return;
_jvm->AttachCurrentThread(&env, NULL);
if(!_nativesCls)
_nativesCls = env->FindClass("com/foo/BaseLib");
if(_nativesCls == 0)
return;
jstring message = env->NewStringUTF(text);
if(!_sendStr)
_sendStr = env->GetStaticMethodID(_nativesCls, "onMessage", "(Ljava/lang/String;)V");
if(_sendStr)
env->CallStaticVoidMethod(_nativesCls, _sendStr, message);
//env->ReleaseStringUTFChars(message, text); // <----- * NOT WORKING
}
如果我运行此作为的是,它工作正常,直到内存满了,我得到:
If I run this as is, it works fine up until memory fills up and I receive:
ReferenceTable溢出(最大值= 512)
我想加入上面的注释行会解决这个问题,但它只是使应用程序在这一点上弹了出来。
I thought adding the commented line above would fix the issue but it just causes the app to bomb out at that point.
有什么建议?
推荐答案
DeleteLocalRef()。就像被内JNI分配的任何其他Java对象。然而,这将是自动垃圾收集一旦JNI方法返回。详情点击这里:的
DeleteLocalRef(). Just like any other Java object that was allocated within JNI. However, it will be automatically garbage-collected once the JNI method returns. Details here: http://download.oracle.com/javase/1.3/docs/guide/jni/spec/design.doc.html#1242
这篇关于如何释放是从本地code回Java发送的jstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!