简体   繁体   English

JNI错误:本地引用表溢出512个条目

[英]JNI error : Local reference table overflow 512 entries

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. 它执行了很多次。在某些时候,它在jobject nvarObject = env-> GetObjectField(var1,nvar1)时崩溃,给出错误JNI错误:本地引用表溢出512个条目。

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

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. 通过在cls引用上调用DeleteLocalRef可以使您cls正确的轨道上,但是请注意, GetObjectField还返回一个jobject ,因此在退出函数之前,也应删除在此返回的引用。

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. 执行此操作的另一种方法:在循环中调用的函数的顶部,在返回函数的任何位置之前调用PushLocalFrame( env, 5 )并调用PopLocalFrame(env) 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. 第二个参数是您要在框架中使用的本地引用的数量-如果在函数执行期间需要5个以上的本地引用,请使用大于5的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM