3
\$\begingroup\$

I've created a relatively simple game using libgdx, but the RAM usage when I start up the game on my Android device is roughly 600-700 mb, but the CPU usage is only about ~0.05%. I've downloaded a game which seems to use similar components to mine, and its RAM usage is only ~100-200mb.

I use an AssetManager to load all of my assets, which are fair in size (the largest asset I have is probably my main game theme song which is ~3mb; all other graphic assets are ~1-2mb).

Are there any tips for how I can reduce the RAM usage of my game?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Do you load all of your assets up-front or do you load them only when you need them? \$\endgroup\$
    – bornander
    May 6, 2016 at 20:30
  • \$\begingroup\$ @bornander I load all of my assets in my AssetManager class using manager.load(...), then create an object of my AssetManager class at the start of my program. I then pass this object to various files, and use manager.get(...) for any particular assets from my AssetManager class that those files may need. \$\endgroup\$
    – Peter
    May 6, 2016 at 20:48
  • 1
    \$\begingroup\$ Whether you like it or not, the Java runtime is going to consume a huge amount of RAM. Most games don't use Java so they're not comparable. \$\endgroup\$ May 7, 2016 at 1:21
  • \$\begingroup\$ Although you might be rubbing the garbage collector the wrong way, you are building an app for the JVM, with the JVM comes a very resource hungry memory management system and this memory usage is fairly ordinary for small games that haven't been heavily optimized. \$\endgroup\$
    – user5665
    May 7, 2016 at 9:46

1 Answer 1

3
\$\begingroup\$

The Android memory profilers that comes with the Android Developer Tools will allow you to figure out what is consuming your memory.

It comes in three parts;

  • Memory Monitor (this is used to find performance problems, so we can ignore this one for this particular problem).
  • Tool Heap Viewer
  • Allocation Tracker

Using the Heap Viewer you can take snap-shots of the heap when your game is running and by comparing the graphs you can figure out what is consuming a lot of memory and how that changes over time.

When you've figured out what is consuming too much memory you can use the Allocation Tracker to figure out where in the code that memory is being allocated. The Allocation Tracker is more difficult to work with but there's good insight to be found using it if you manage to climb the steep learning curve.

The tools are available in IDE if you're using Android Studio or Eclipse.

More details on the tools can be found here.

If you find that all the memory allocated is correct in the sense that you don't allocate twice and forget to release then the next thing to look at would be when you actually need all the data. For example, is your game structured so that you can load a certain subset of the resources per level, and unload the unused ones from the previous level.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .