Memory Leaks

Hey all just another quick question,

If i do something like the following in my C code do i have to explicitly free it to stop memory leaks?

Here is an example of my code:

//Create a jintArray

jintArray = sally;

int sally_size = 3;

sally = (*env) -> NewIntArray(env, sally_size);

//Populate my jintArray with an int array called mary

(*env) -> SetIntArrayRegion(env, sally, 0, mary_size, mary);

//Is this line necessary?

(*env) -> ReleaseDoubleArrayElements(env, sally, 0);

//Return the jintArray

return saly;

Answers on a post card please?

[635 byte] By [frostywintersa] at [2007-11-26 15:37:31]
# 1

The short answer is no. The longer answer is that you should read the JNI spec at http://java.sun.com/j2se/1.5.0/docs/guide/jni/spec/functions.html in particular the section on ArrayOperations. It details when calling ReleaseDoubleArrayElements is necessary, which is to free the result returned by GetDoubleArrayElements. I don't think the code you typed should even compile since sally is a jintArray and you're trying to free it as a double*.

tom

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