JNI general rules

Hello there,

I am using the JNI to access a library written in c. And i just have two small questions.

If i give my JNI method arguments such as a jint do i have to explicitly delete this in the c code?

Ok now if my method in c code creates a jintArray do i have to explicitly delete this to?

Basically do i only have to explicitly delete variables if i "bring them in" to the c code. So that would mean i have to explicity delete arguments to my method by not variables created within the c method implementation.

Answers on a postcard.

Message was edited by:

frostywinters

Message was edited by:

frostywinters

[674 byte] By [frostywintersa] at [2007-11-26 15:23:41]
# 1
Stuff passed to the C code from java does not have to be deleted in Cthey are java objects and the java garbage collector will get rid of them.The same is true for java objects created from C.
bschauwejavaa at 2007-7-8 21:38:58 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
See JNI API Enhancements for Java 1.6.x at http://java.sun.com/javase/6/docs/technotes/guides/jni/
vitallisa at 2007-7-8 21:38:58 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

You can't explictly delete java objects so I assume your question is about what JNI resources have to be explicitly freed. The JNI spec is generally pretty clear about whether a resource needs to be explicitly freed. The 1.5 version is at http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/jniTOC.html. In particular I'd recommend reading the section on references to Java objects http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/design.html#wp16785. Chapter four documents the individual functions in the JNI interface.

tom

neverevera at 2007-7-8 21:38:58 > top of Java-index,Java HotSpot Virtual Machine,Specifications...