Reputation: 35
My game is composed of Main Menu (25 objects -> it is a dynamic menu, everything is moving), Game Over (3 objects), Game Screen(15 - 20 objects), Game Shop (40 objects)... So my game has used about 50mb of ram and then steadly increased, because well I am creating so many objects!
But of course I just used the command System.gc() in my Main Menu and now it is always at about 25mb, and there seem to be no problems! But people say it is bad practice to to that.
But the screens get destroyed, and I don't want to keep the objects that would waste my RAM, so it seems like this is the only solution!
Upvotes: 2
Views: 1119
Reputation: 5869
I suggest that you use the libgdx way of memory management, make sure that you dispose all objects that implements disposable, you can find a list of disposable objects here, also you can use object Pooling which is a common pattern for memory management used in libgdx :
regards to libgdx wiki :
Object pooling is the principle of reusing inactive or "dead" objects, instead of creating new objects every time. This is achieved by creating an object pool, and when you need a new object, you obtain it from that pool. If the pool has an available (free) object, it is returned. If the pool is empty, or does not contain free objects, a new instance of the object is created and returned. When you no longer need an object, you "free" it, which means it is returned to the pool. This way, object allocation memory is reused, and garbage collector is happy.
Upvotes: 3