One of the most obvious differences between Java and C++ is the model for managing resources. In Java, you simply drop references to unused objects and trust the garbage collector to reclaim memory when necessary. In C++, you typically take explicit control of resource deallocation. The JNI boundary must provide a sensible mapping between these two programming styles. There are four interesting cases to consider:
How does native code communicate with the garbage collector to manage the lifetime of Java objects?
How does Java code manage the lifetime of native objects?
How does JNI handle arrays?
How does JNI handle strings?
Arrays are a special case because Java accesses and stores arrays in a way that is not necessarily ...