Reputation: 155
I'm testing my game and I've encountered a problem. My main game class is restarting (not the whole application) when the user dies, but whenever it restarts, it just runs slower and slower. I'm thinking of a possible memory leak.
I'm switching over from a screen to screen with setScreen(Screen sc) method. I'm also cleaning up in dispose() method, and I can't find the reason.
So I'm asking you to maybe point me in any direction what could be causing my app to slow down on the restart?
It might be ShapeRenderer since I'm rendering a huge amount of shapes in loops- maybe that's the problem? But the app works perfect unill I call a new instance of the main game class.
There is too much code to post it, so I'm sorry for the huge amount of text. I really hope you could somehow point me what could be wrong!
Upvotes: 1
Views: 1799
Reputation:
Something that might help you. Use jmap ( http://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html ). jmap displays you which instances of objects are currently held by the jvm. Just make a runnable jar of your game, start the game, check jmap, die a bit and then check jmap again. Maybe you see an increase in Texture-Objects thus you might not be cleaning up some of those ( it is easy to forget some if you are using an AssetManager).
Upvotes: 4
Reputation: 4529
If you look at ScoreScreen you will see that you are not disposing of the Texture you load.
I would highly suggest you take a look at the Asset Manager tutorials and guides for libgdx to avoid this in the future.
Edit:
Side note, your code isn't bad at all so don't be ashamed by it. In fact I would say its better than average :).
Upvotes: 4
Reputation: 25177
Using a tool that tracks memory allocations will be far more useful than a code review.
Use the Eclipse DDMS memory tracker: http://developer.android.com/tools/debugging/ddms.html#alloc
Upvotes: 1