The memory consumption of huge memory in Android graphics? - libgdx

I currently have an empty LibGDX application that does nothing . He does nothing and does not update anything. This is just an empty Screen . When I deploy the application to android, I welcome some terrifying amounts of memory. Using DDMS, I create the following dump heaps when the application is running on my device:

enter image description here

The most significant memory usage is the allocation of a 1-byte array of 13.163 MB. Isn't that half a heap ?!

I checked the distributions and saw that nothing indicates the allocation of this size:

enter image description here

Now, using the Eclipse MAT, I am analyzing a heap dump:

enter image description here

Thus, memory usage still comes from byte [] arrays. Analyzing the byte [] section below, I came to the following:

enter image description here

Now I see that the huge bytes [] are allocated from the Android graphics. I don’t even draw anything! Is there a way I can avoid half of the heap of the Android application in this application. Does this just cause the excess garbage collection to happen when everything happens, or is this normal and I just need to deal with it?

Note. I run this on a Samsung Galaxy S4 with libGDX version 1.4 (or any other version)

UPDATE: I did not find that an allocation of arrays of 14-13 MB is normal for applications, but I still have a problem. My heap size is too small. If the Android graphics account for half of my heap, I have little space for anything useful, and the garbage collector goes crazy. In another application, I created an older version of libgdx (certainly a poorly encoded application), and the heap size is 73 MB. How to increase heap size? I assume that 73 MB is large enough, and as you can see, most of them are not used. Here are the old application heap statistics: enter image description here

+8
java android heap memory libgdx
source share
3 answers

After Android version 2.3, you can do nothing about heap size other than using the android: largeHeap attribute.

There are two ways to cheat if you want a large heap not to matter:

  • Using the built-in api to allocate memory . Not a good idea, because it increases complexity and if you do not plan to do something in your own code,
  • Allocating an unnecessary large object before execution to get the desired heap space . Although this will give you enough space for the heap once, it is not guaranteed that the heap size will remain unchanged.

However, the initial heap size is not a problem if it is changed if necessary. My opinion on memory management in the life cycle of the game is slightly different from the two things listed above and what you are probably doing.

For level or stage, etc. You do not have to allocate memory at the exact time when you need it. This will not only cause stuttering when allocating memory, but it will also stutter due to possible memory I / O. Anything, such as sounds, graphics, fonts, etc., must be prepared to the level. This is why most games have a loading screen. You must prepare everything you can do before you start the game.

For a small stage, doing this is normal, but still not good. As things get complicated, productivity decreases. Many games (for example, sports games, racing games, etc.) perform distribution before the start of the game. Others do this as much as possible . Some games in the open world (for example, GTA) do not load all the map objects on the map, but they have a distance to drawing, so they draw as they move on the map, and they delete the farthest objects from memory when there is no more space in the memory.

[The reason your application with the old version of LibGDX gets larger than the heap size is probably the allocation that caused the heap size to increase and the release that freed part of the heap for you to get a good 30% usage.]

+6
source share

You can assign this attribute value in the Android manifest:

android: largeHeap = "true"

Note that this will only work on Android 3.0+

+1
source share

Right-click on the selected object, select "trace to GC root", "exclude weak links"

http://www.youtube.com/watch?v=_CruQY55HOk

+1
source share

All Articles