I have a newbie question. This is a screenshot of Memory tab in Android studio. Can someone provide some approximate data about what is an acceptable memory consumption? Are there boundaries limiting max memory usage? Should I be worried if allocated memory is around 11Mb?
Asked
Active
Viewed 585 times
1
-
Most games will use way more than 11mb, so you should be OK. Keep the amount of available memory in mind while developing though. Requesting a large heap (In androidmanifest I believe) will also gibe you more memory if you need it. – Jonas Czech Jan 05 '16 at 15:01
-
16MB is the limit on some really old devices. Probably not on any device less than three or four years old. The limit only applies to the Java heap. Native memory is not limited per-app. The vast majority of your memory use in a game is probably native memory from your textures and pixmaps. Most of your Java memory use is probably from your code (classes, enums, primitives) and maybe sounds. If you use Proguard, you'll probably see it drop by quite a bit because of all the Libgdx classes you're not using. – Tenfour04 Jan 05 '16 at 15:08
-
Thanks for comments. I noticed that on some devices memory allocated is lower. Why is that? On one device, the memory allocated was only 4Mb and the app crashed after the start with no error message displayed on screen. Is it possible that the allocated memory was to low and that caused the crash? The question can be found here http://stackoverflow.com/questions/34616201/libgdx-game-crashes-on-some-devices – potato Jan 05 '16 at 16:29
1 Answers
2
It does seem like you don't have much free memory and that the allocated memory should be more. I had the same problem and it was because I was not closing my cursors properly and also because I was not recycling the bit map memory for graphics I was getting from files instead of from the drawable resources. You can tell how much memory you have available to your app:
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
int memoryClass = am.getMemoryClass();
Runtime rt= Runtime.getRuntime();
long maxMemory = rt.maxMemory();
long freeMemory = rt.freeMemory();
Log.d("Memory Available", "memoryClass:" + Integer.toString(memoryClass));
Log.d("Max Memory Available", "max memory:" + Long.toString(maxMemory));
Log.d("Free Memory", "Free Memory: " + Long.toString(freeMemory));

Kristy Welsh
- 7,828
- 12
- 64
- 106
-
Thanks for stopping by. I noticed that Allocated memory differs when the app is run on different device. Do you, by any chance, know why this is happening? – potato Jan 05 '16 at 16:22
-
@krompir2 - for my app, the allocated memory varied wildly, depending on the device. A Note 3 chewed up 3 times as much allocated memory than a Nexus 7 table. – Kristy Welsh Jan 05 '16 at 17:21