Is using C global variable in JNI on android acceptable?
If so, I'd like to know the life-cycle of it.
When a.cpp is connected to b.java and instance of b is created(is global variable initialized at this point?) and destroyed(is global variable destroyed at this point?).
In a nutshell, global variable in C side share it's won life-cycle with connected Java instance?
CodePudding user response:
The lifetime of native objects is tied to the lifetime of the native library that hosts them. This, in turn, is governed by the lifetime of the Java ClassLoader that loaded the library:
In addition, native libraries can be unloaded when their corresponding class loaders are garbage collected.
In Android applications that will never happen, so you can assume that your native objects survive as long as the application does.