Some resources are not cleaned by the garbage collector. You need to dispose them manually, in order to save memory. You just need to call .dispose()
You can find more information about libGDX memory management here.
There is also a list with all resources that implement a disposable interface.
For example, you can dispose a Polygon Shape after using it to create your Fixture:
public void create() {
FixtureDef fDef = new FixtureDef();
Fixture fixture;
PolygonShape shape = new PolygonShape();
shape.setAsBox(w, h, position, angle);
fDef.isSensor = true;
fDef.shape = shape;
fixture = body.createFixture(fDef);
shape.dispose(); //You can dispose the shape.No longer needed.
}
However, you have to pay attention before disposing something that is still needed in your code:
public void setWalkLeftAnimation() {
assetManager.load("walk_left.pack", TextureAtlas.class);
assetManager.finishLoading();
atlas = assetManager.get("walk_left.pack");
walkingLeft = new Animation(1/12f, atlas.getRegions());
// Don't dispose it,you won't be able to render the animation.
//assetManager.dispose();
//atlas.dispose();
}
Dispose the Asset Manager and Atlas in the proper dispose method:
@Override
public void dispose(){
assetManager.dispose();
atlas.dispose();
//Dispose it here with other resources.
}
ApplicationListener
. Can you show us your class code? \$\endgroup\$