2

I've developed a game with libgdx. I've tried to keep memory consumption as low as possible by doing the following:

  1. Use Pooling where possible.
  2. Limit SpriteBatch's size

When I run the game on my phone (Nexus 5x) from Android Studio, my game runs smoothly and it seems that memory consumption is indeed reasonable: The memory consumption is usually under 23MB (I see this via the memory monitor). However, when I go to the memory tab on my phone (Settings --> Memory --> Memory used by apps) I see the following: enter image description here

A shocking "Maximum memory use" of 1.2 GB for my game. Way above any other app.

My question(s):

  • What does this number mean? Does this mean that at one point my game took up 1.2 GB of the RAM?
  • How can that be if the memory monitor never showed a consumption of over 25MB?
  • Seeing that the game does run smoothly should I try to get this number down? If yes, how can I do this?
Lovis
  • 9,513
  • 5
  • 31
  • 47
asherbret
  • 5,439
  • 4
  • 38
  • 58

1 Answers1

2

You're mixing up native memory (RAM, as shown on the screenshot) and VM memory.

In the memory monitor, you only see the heap (so the memory that was allocated for the VM on which your app is running), but not the actual RAM. This maximum heap size is limited by the system (see e.g. https://stackoverflow.com/a/9940415/1096567 for examples).

Libgdx is using OpenGL via a JNI and is therefore also using the RAM directly.

To investigate your RAM usage in general you need other tools than the Memory Monitor, see e.g.: How do I discover memory usage of my application in Android?

I don't know your app, but 1.2GB seems a bit high. If you're not using Texture Atlases & the Texture Packer, it's probably a good place to start optimizing. Also be sure to dispose all Disposables (like BitmapFont). Here is a detailed list.

Community
  • 1
  • 1
Lovis
  • 9,513
  • 5
  • 31
  • 47
  • Thanks for clarifying the difference between native memory and VM memory! That was indeed confusing me. I'm already using Texture Atlases, and my game is not so rich in graphics. I have 5 Texture Atlases which, according to the Texture Packer I'm using, will take up around 12MB of RAM total (for all 5). What I will check is whether or not I'm creating some of the same Texture Atlases multiple times. Is there anything else I should check? – asherbret Mar 01 '16 at 10:33
  • @user2016436 I'm not a libgdx-pro but you should check whether you disposed all disposables: https://github.com/libgdx/libgdx/wiki/Memory-management. I also don't know enough about your app, to know your memory hotspots. You need to profile it yourself. – Lovis Mar 01 '16 at 10:41