String and garbage collection

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

String and garbage collection

Postby gbattez » Wed Sep 11, 2019 11:15 am

I display a score in my game loop of my android game with
Code: Select all
font.draw(player.score.toString, x, y)

where 'font' is a BitmapFont, the problem is that the 'toString' method creates a string 60 times per seconds which will eventually run the gc and cause stuttering.

Is there a way to not create objects every time we want to render text ?
Posts: 3
Joined: Fri Dec 22, 2017 8:37 am

Re: String and garbage collection

Postby evilentity » Wed Sep 11, 2019 3:37 pm

Not really. You can call toString only if score changes to reduce the gc pressure.
Looking for a freelancer? PM me!
Check out libgdx discord server!
Posts: 4867
Joined: Wed Aug 24, 2011 11:37 am

Re: String and garbage collection

Postby Magnesus » Thu Sep 12, 2019 2:10 pm

And use StringBuilder.
Posts: 1709
Joined: Sun Sep 25, 2011 3:50 pm

Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest