Android static data not reset


A problem with the Android NDK is that is does not clear static data each time your app is started. this is because once the shared library is loaded in memory, it does not kick it out unless it’s short of memory.

unfortunately, this is bad if you app quits or is made to quit or is quitted for you somehow.

There are also problems with static data that might go “stale” if left too long. For example `Time::getCurrentTime’ uses a static for wraparound. this will go stale after around 50 days.

Another problem is that `getCurrentTime’ returns yesterday if i’ve run the app yesterday. quit it and later run it today. in fact, it never advances time.

Unfortunately, everyone out there seems to think you should either not use statics, should never quit your app or should write code to manually reset them.

however, i’d like to find a proper way to clear statics.

here’s what i have, but it’s not nice, for some reason this works,


[quote]JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity))

android.shutdown (env);

// XXX
// This is HACK to reset static data. 


– hugh.



I guess exit() will work, but does it also kill the java process?

Doing a bit of searching, I found this:


How do i know if it kills java.

Actually, im pretty sure im killing everything in my case anyhow. i’ve been trying to get my app to quit when i want it to. for some reason, Android apps like to continue in some sort of stopped state. really, i dont see why they do this; if an app doesnt need to do anything when you quit and also is quick to start, why not just start it as normal.

if there’s a way to manually unload the shared library, then this might be a good plan in general, otherwise you’ll have to manually reset any Juce static data which, i think, is not right either,