1. Check out our app, Forums for Android! Download and leave feedback here!

Managing String Allocations, Garbage Collections in a Game Loop

Discussion in 'Application Development' started by AlbertPucciani, Nov 11, 2010.

  1. AlbertPucciani

    AlbertPucciani Well-Known Member
    Thread Starter
    36

    Oct 2, 2010
    71
    8
    36
    Computer Programmer
    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?
     

    Advertisement

  2. AlbertPucciani

    AlbertPucciani Well-Known Member
    Thread Starter
    36

    Oct 2, 2010
    71
    8
    36
    Computer Programmer

Share This Page

Loading...