Android static data not reset

For Android specific issues

Android static data not reset

Postby hugh » Mon Jun 11, 2012 6:18 pm

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

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.
User avatar
hugh
JUCE UberWeenie
 
Posts: 165
Joined: Sun Apr 25, 2010 8:04 pm
Location: London, UK

Re: Android static data not reset

Postby jules » Tue Jun 12, 2012 9:53 am

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
User avatar
jules
Fearless Leader
 
Posts: 17189
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: Android static data not reset

Postby hugh » Tue Jun 12, 2012 5:18 pm

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,
User avatar
hugh
JUCE UberWeenie
 
Posts: 165
Joined: Sun Apr 25, 2010 8:04 pm
Location: London, UK


Return to Android

Who is online

Users browsing this forum: No registered users and 1 guest