Steve M
Steve M

Reputation: 9784

Is their a guaranteed lifetime for file-scope variables declared in .c and .cpp files (JNI)?

When calling JNI functions from Java in an Android app using JNI, is their a guaranteed lifetime for variables declared at file-scope? We call this function a few times, can the Android system unload our program from memory without terminating the app's process in order to conserve memory in between calls? Is our variable lifetime guaranteed for the life of the process?

#include <stuff>

int counter = 0;

extern "C" void com_package_Class_dostuffFromJava(JNIenv.....)
{
    LOG("Counter: %d" , counter);
    ++counter;
}

Upvotes: 0

Views: 322

Answers (1)

user207421
user207421

Reputation: 310980

Any operating system can swap or page memory, but I don't see why it concerns you. The 'guaranteed life' of a file-scoped variable in C is the life of the process.

Upvotes: 1

Related Questions