Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DeleteLocalRef after SetObjectArrayElement when building array in JNI

In JNI I'm constructing a large array by calling SetObjectArrayElement() to insert a java object created locally in the JNI code.

My question is, after inserting the object into the array using SetObjectArrayElement(), does the array store a reference such that I can use DeleteLocalRef to free the local reference to the object that is inserted?

like image 213
Noah Watkins Avatar asked Dec 06 '10 19:12

Noah Watkins


1 Answers

Yes.

The jobjectArray points to an array of references.

When you set a member of that array to a local reference, you've made a second reference to the object. If you delete the local reference, the reference in the array remains. The garbage collector will not dispose of the actual object until there are no remaining reachable references.

like image 142
Andy Thomas Avatar answered Oct 06 '22 02:10

Andy Thomas