Android static data not reset

3 posts / 0 new
Last post
hugh
Offline
Last seen: 7 months 1 week ago
Joined: 25 Apr 2010 - 20:04
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,

juce_android_windowing.cpp

Quote:
JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity))
{
JUCEApplicationBase::appWillTerminateByForce();

android.shutdown (env);

// XXX
// This is HACK to reset static data.
exit(0);
}

-- hugh.

jules
Offline
Last seen: 9 hours 29 min ago
Joined: 29 Apr 2013 - 18:37
Re: Android static data not reset

Yikes!

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

Doing a bit of searching, I found this: http://codethesis.com/sites/default/index.php?servlet=4&content=2

hugh
Offline
Last seen: 7 months 1 week ago
Joined: 25 Apr 2010 - 20:04
Re: Android static data not reset

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,