JNI错误:本地引用表溢出512个条目 [英] JNI error : Local reference table overflow 512 entries

查看:176
本文介绍了JNI错误:本地引用表溢出512个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的功能如下所示。并且它被执行了很多次。在某些时候它崩溃在jobject nvarObject = env-> GetObjectField(var1,nvar1)给出错误JNI错误:本地引用表溢出512个条目。

My function looks like below. And it is getting executed for a number of times.At certain point it is crashing at jobject nvarObject = env->GetObjectField (var1, nvar1) giving error JNI error : Local reference table overflow 512 entries.

任何人都可以调查这个问题并提出一些建议。

Could anyone look into this issue and throw some light.

推荐答案

返回<的所有JNI方法code> jobject 或类似的对象引用正在引用表中创建本地引用。将控制权返回给JVM时,这些引用会自动清除,但如果要创建许多引用(例如,在循环中),则需要手动清理它们。

All JNI methods that return a jobject or similar object reference are creating local references in the reference table. These references get automatically cleaned up when you return control to the JVM, but if you are creating many references (for instance, in a loop), you'll need to clean up them up manually.

通过在 cls 参考上调用 DeleteLocalRef ,你走在正确的轨道上,但请注意 GetObjectField 还返回 jobject ,因此在退出函数之前返回的引用也应该被删除。

You're on the right track by calling DeleteLocalRef on the cls reference, but notice that GetObjectField also returns a jobject, so the reference returned there should be deleted before exiting the function, as well.

还要确保在从错误条件返回之前清理所有现有引用!

Also make sure to clean up any existing references before returning from error conditions!

另一种方法:在你在循环中调用的函数的顶部,调用 PushLocalFrame(env,5)并调用 PopLocalFrame(env)在您返回的函数中的任何位置之前。这将自动清除在该函数调用期间创建的任何引用。第二个参数是帧中需要的本地引用数 - 如果在执行函数期间需要超过5个本地引用,请使用大于5的值。

Another way to do this: at the top of the function that you're calling in a loop, call PushLocalFrame( env, 5 ) and call PopLocalFrame(env) before any place in the function where you return. This will automatically clean up any references created during that function call. The second argument is the number of local references you want in the frame -- if you need more than 5 local references during the execution of the function, use a value higher than 5.

这篇关于JNI错误:本地引用表溢出512个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆