Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android java, get more allowed memory usage

I am creating this game for android and I have a few question about memory usage. When we were coding within our ignorance we had our app using about 40mb memory but that made a test phone crash (Xperia Arc (something, something)) which went out of memory. We then coded it smarter with the memory and got to about 20 mb. We have googled alot and we've seen peoples posting that most mobile phones are limited to 16 mb and others 32 mb. BUT, we've also compared with other applications like angry birds, which are using about 129 memory (which works fine on the Xperia arc that crashes over 32 mb with our app).

My question is then: can we somehow get to use more memory than 16 / 32 mb or how does the apps that uses way more do?

Some people says that you can use other processes to handle memory and get another 16 / 32 mb for that process, if that true. Would that be doable for an average programmer?

like image 503
Rasmus Avatar asked Jan 14 '23 22:01

Rasmus


2 Answers

I know that G1 will only give 16mb for apps, but it is a very old one. Most popular devices could all provide 32/64mb. The amount of memory always depends on the screen size.

The android:largeHeap in manifest.xml is just what you want, but i haven't used it ever. It's said that the effect of this attribute differs in different devices.

like image 138
faylon Avatar answered Jan 21 '23 05:01

faylon


Pre-Honeycomb: Angry Birds and a lot of games do their programming or memory allocation using native C++ code in the Android NDK. If you allocate memory outside of the JVM, it doesn't count towards your heap limit so you're limited only by hardware. The catch is, of course, you are solely responsible for the memory management.

Honeycomb and above: As faylon suggested, android:largeHeap is the way to expand your heap limit to really large, though you're still under the bounds of the phone's manufacturer. Their interpretation of "largeHeap" may be 64MB instead of 32MB, or they could in theory just not give it to you. Thus, you have to use it in conjunction with getLargeMemoryClass() to make sure your memory is available. The NDK option is still available.

like image 45
DeeV Avatar answered Jan 21 '23 05:01

DeeV