JNI error : Local reference table overflow 512 entries(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.
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.
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!
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 个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JNI 错误:本地引用表溢出 512 个条目


基础教程推荐
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01