Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Could anyone look into this issue and throw some light.

like image 716
rvp Avatar asked Jan 04 '14 06:01

rvp


1 Answers

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.

like image 139
Jason LeBrun Avatar answered Oct 11 '22 14:10

Jason LeBrun