asherbret
asherbret

Reputation: 6018

Very high "Maximum memory use" for libgdx game

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):

Upvotes: 2

Views: 1057

Answers (1)

Lovis
Lovis

Reputation: 10047

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.

Upvotes: 2

Related Questions