I am currently porting a game developed in C # (for Windows Phone) to Java (Android).
We are having memory problems in the Java version, which after profiling seems to come from a huge number of String objects in memory, obviously due to the unchanging nature of String . Now I was able to trace this down to a method that displays the player on the screen, where Integer.toString() used every time the score changes (many times per second). I can’t use StringBuilder (this is what we have in the C # version) because the text rendering methods of the frame we use only accept String as arguments, so the conversion happens anyway.
Is this a common problem in Java? Can anyone recommend a solution (besides contacting the developers of the framework to ask them to change their methods!)?
Update:
The game is very fast, and the score is partially based on the time elapsed since the beginning of the current “stage”. It is updated 15 times per second.
We won’t refer to the line, but I think that perhaps the structure is leaking or duplicating these lines, so I am trying to study this (it is not a public structure and, as far as I know, it hasn’t been used for this kind of fast-paced game )
Unification is a good suggestion, and I thought about trying to do it, but the rating system must be changed to have a fixed set of values.
source share