1

I have a chess app on my 2012 Nexus 7 (running stock Android 4.3, with a few small background services) that allows me to set the size of an internal hash table used by the chess engine. Larger hash tables increase the performance of the chess engine, but it is ultimately limited by the RAM available on the tablet. Typically, the Settings app indicates that around 450-500 MB of RAM is free.

How much memory should I allow the app to use, and how much should I leave free for the system? As I don't want to change this setting too often, can I rely on this amount of memory being available every time I use the app? (Note that the amount of memory used must always be a power of 2.)

The other questions and answers I've read haven't really answered this question, so I don't believe this is a duplicate.

1
  • If you want more thoughts on this topic, consider posting this question on the Chess SE site (chess.stackexchange.com). Cheers.
    – user57616
    Commented Apr 2, 2014 at 13:59

2 Answers 2

4

If you've read around, then you'll already have read that the idea of "free RAM" is a bit of a nonsense for Android. PC operating systems take an app out of RAM as soon as you quit it, which leaves empty space that the PC probably has to spend power on filling again afterwards - probably with the same app next time you run it. Android tries to avoid this waste by leaving apps in memory after you stop using them or after they finish running, so that they're ready to run again next time. If it needs more RAM for an app, only then does it get rid of these cached processes.

Android will first get rid of cached processes, based on how soon it thinks it's going to need them again. If it still needs more RAM for the foreground activity, it'll get rid of background services (which sync your email etc. but aren't directly visible). If it still needs more RAM, it'll get rid of activities that are directly accessible but aren't currently visible, such as the launcher, the activity you'll go back to when you press back (maybe even in the same app as the activity that's running), or the greyed-out activity that's partly visible behind a dialog. This way, even if you have no free RAM, Android can free up quite a lot of RAM for the foreground activity: all the RAM on the device, except that needed by Android itself.

I suggest to work out the best setting using trial and error. Without more knowledge of the app, I can't predict the effect of having the setting too low: perhaps the AI will make worse moves, or take longer to decide. If the setting is too high, you'll notice that when you leave the chess game you have to wait for the previous app to launch: this is particularly noticeable when it's the launcher, and you get a spinning progress indicator instead of the list of apps.

If this were one of my apps, I'd consider this a bug. It's bad form to give the user a setting with no way to know what value to set. The app has more information about how much RAM the device has and can make available than you do: it should decide itself.

0

If an Android app provides a way to configure the amount of RAM used to trade RAM for lower CPU requirements the only way to decide the "correct" amount is to try different values and scale the value down if the whole system gets too slow.

As explained by Dan Hulme, Android will automatically close apps until the foreground app gets the RAM it needs. If your chess app eats nearly all the memory, the whole system will get slow because it will be constantly closing apps and restarting apps to e.g. check if you have new mail and to check if you have new facebook notifications - when RAM is low both cannot be done in paraller but both apps will repeatedly do their thing so Android will end up stopping and starting those apps all the time. Note that stopping and starting apps eats lots of battery even if you didn't have visible performance problems.

Note that the correct setting depends on the other apps you're running on your device. I'd start with 100 MB and test the performance. Then test 50 MB and 200 MB and see if either value makes the chess program faster without slowing down the overall system performance.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .