2
\$\begingroup\$

I'm developing a multi-platform game in libGDX. Sometimes there is a huge issue with memory. The game used to stick a lot. In fact, I even used pooling.

Is there any method to check the memory leakage in libGDX?

\$\endgroup\$
1
  • \$\begingroup\$ The JVM will never give memory back to the operating system after it allocated it, so if you're checking memory usage in the task-manager it might be just a peak in memory-usage some time ago, but the JVM still holds onto the free memory. \$\endgroup\$
    – tkausl
    May 12, 2016 at 16:50

1 Answer 1

2
\$\begingroup\$

You can use a memory profiler like JProfiler(trial/paid) or JVmonitor(free) to take a snapshot of the heap when your program starts to eat up memory. These programs will at the very least tell you what type of object is eating up your memory. These of course will only work for the Desktop version of your app.

Also ensure that you are using pooling correctly. Specifically, the moment that you are done with an object created from a Pool, make sure you call free() on that object. Otherwise the next time you call obtain() the Pool will create a new object.

Also see if there is anywhere in your code that you are thrashing a pool. Meaning, if you call obtain() 1500 times in a row, then you will create 1500 objects. These objects will stay in memory until you clear the pool (depending on the max setting of the pool). You may want to redesign that part of the code so that you don't hit the pool so hard all at once.

Check out the Memory Management page of the libgdx wiki. It has a list of all the objects that must be disposed when you are done with them. If your game changes states/screens a lot, make sure that the resources you no longer need from a state gets disposed between states.

If you aren't already, make use of the AssetManager class. It uses reference counting so that everything you load can be shared between all users that need it. This is critical for large unmanaged objects like textures. This also means that once the reference count drops to 0, AssetManager will dispose of the asset for you.

\$\endgroup\$
0

You must log in to answer this question.