I’m creating Java wrappers for some C code using JNI. There are dependencies on the C side that look like this:
a = make_a();
b = make_b(a);
On the Java side I use class A and class B to hold references to the output of make_a() and make_b, along with various operations. Further, class B depends class A sticking around.
How can I create a dependency between the two classes from within JNI?
Update
I need class A to not be GC’d while class B is in use, and I need to create this dependency from within JNI.
I think what you want is NewGlobalRef/DeleteGlobalRef. This will let your JNI hang on to an object reference. Be careful– this is an easy way to create memory leaks as its up to you to delete the reference!
Here are some links to get you going: