java new byte 释放_java – JNI NewByteArray内存泄漏

我有一个

@L_404_0@方法来处理位图并返回一个String.

当我从JNI(VS 2010)中调用此方法时,它可以工作,但是如果我多次调用该方法,

这个过程的记忆长大直到崩溃.

使用大量内存的指令是:

jbyteArray jBuff = _env->NewByteArray(b->Length);

我的代码:

static jobject staticArray=0;

System::String^ MyClass::ExecuteJavaMethod(System::Drawing::Bitmap^ bmp)

{

JNIEnv *_env;

System::String^ out;

unsigned const char * buff;

int res = jvm->AttachCurrentThread((void **)&_env,NULL);

if (jvm->GetEnv((void**) &_env,JNI_VERSION_1_6) != JNI_OK)

{

return "GetEnv ERROR";

}

//save the bitmap in the stream

MemoryStream^ ms = gcnew MemoryStream();

bmp->Save(ms,ImageFormat::Bmp);

//get the bitmap buffer

array^b = ms->GetBuffer() ;

//unmanaged conversion

buff = GetUnmanaged(b,b->Length);

//fill the buffer

jbyteArray jBuff = _env->NewByteArray(b->Length);

_env->SetByteArrayRegion(jBuff,b->Length,(jbyte*) buff);

//call the java method

jstring str = (jstring) _env->CallStaticObjectMethod ( Main,javaMethod,jBuff);

// _env->ReleaseByteArrayElements(jBuff,(jbyte*)buff),0); //NOT WORKING

//staticArray= _env->NewGlobalRef(jBuff); NOT

//_env->DeleteLocalRef(jBuff); WORKING

//return the string result of the java method

return gcnew String(env->GetStringUTFChars(str,0));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值