• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Managing String Allocations, Garbage Collections in a Game Loop

Hello all,

I've managed to get my allocations down to next to nothing using DDMS (great tool), this has drastically reduced my GCs to about 1 or 2 every 3 minutes. Still, I'm not happy because those usually cause a noticeable delay in the game (on some phones) when you interact with it.

Using DDMS, I know what the allocations are, they are Strings being converted from integers used to display game information to the HUD.

I'm basically doing this:

int playerScore = 20929;
String playerScoreText = Integer.toString(playerScore);
canvas.drawText(playerScoreText, xPos, yPos);
etc.....

This happens once each frame update and the HUD system is modular so I plug things in when I need and this can cause 4 or 5 hud elements to allocate Strings and AbstractStringBuilders in DDMS.

Any way to reduce these further or eliminate all the String allocations and just reuse a String object?
 
Back
Top Bottom