free java array build from JNI ???

L

lionel pacoud

Hi,
I have a pb. I'm using JNI to speak from java to C.
I build in the C code a java array and I return it to the java

jshortArray array = (*env)->NewShortArray(env, compressedImgSize);
if(array) {
(*env)->SetShortArrayRegion(env, array, 0, compressedImgSize,
compressedImg);
}

where compressedImg is a buffer who contains the data that I want to
return.

the java array created (called here "array") will be free by the
garbage collector or I must free it.
(if I must free it, how could i do that. I don't found any things in
the spec.)

well, thanks for your answers.
Lionel
 
S

Steve Menard

lionel said:
Hi,
I have a pb. I'm using JNI to speak from java to C.
I build in the C code a java array and I return it to the java

jshortArray array = (*env)->NewShortArray(env, compressedImgSize);
if(array) {
(*env)->SetShortArrayRegion(env, array, 0, compressedImgSize,
compressedImg);
}

where compressedImg is a buffer who contains the data that I want to
return.

the java array created (called here "array") will be free by the
garbage collector or I must free it.
(if I must free it, how could i do that. I don't found any things in
the spec.)

well, thanks for your answers.
Lionel

You do not need to free it. The reference returned byte the
NewShortArray function is called a LocalReference, and has a lifetime of
current method.

If you return to java code, then the reference management will take care
of it. If you want to keep it reference in native code fro later use,
you need to call CreateGlobalRef so that the GC won't eat it.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top