the memory problem
Hi All,
I am running a jni program, where my program will call a .c file.
I see the .c file sets an array "int bit[10000]" and initializes it. I wonder whether this array will be kept in the memory after I called the .so file. Because I will call the .so file thousands of times, if the memory can not be released, I certainly will run out of memory.
thx for your help
[395 byte] By [
jasoncuia] at [2007-11-26 15:39:02]

# 2
Hi,
It depends where your array is declared.
3 examples :
first : the array is initialized for the whole library instance,
int foo[10000];
void someFunction() {
}
second: the memory is allocated when entering function and freed when exiting
void someFunction() {
int foo[10000];
.....
}
third : the memory is allocated when entering function and nether freed (bad)
void someFunction() {
int* foo = new int(10000); /*or malloc */
.....
}
--Marc (http://jnative.sf.net)