Using DeleteLocalRef after SetObjectArrayElement when building array in JNI
java, java-native-interface
Solution
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.
Problem
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?