Hi all,

I'm writing a game and I'm trying to avoid the GC kicking in and
causing big framerate drops.
I've run DDMS to see what allocations I'm causing and the huge
majority of them seem to fall under 2 categories:

1) class java.lang.String, allocated in java.lang.Integer, allocated
in toString
2) class java.lang.String, allocated in
java.lang.AbstractStringBuilder, allocated in toString

In my game I need to display some stats so there are a few number-to-
string operations.
I went the StringBuilder way with pre-allocated buffers assuming this
will help reduce allocations.

So for example I have a

private StringBuilder m_hitRatio - new StringBuilder(8);

I draw using
canvas.drawText(m_hitRatio.toString(), x, y, paint);

I update using
m_hitRatio.replace(0, 8, String.valueOf(calculatedHitRatio));

In some cases if I'm passing a normal string to a method I also use
Integer.toString(myValue);
I'm guessing all of the above is the reason my GC is working overtime!
Are there better ways (using canvas) to manipulate and render text/
numbers on screen?

cheers,
kk.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to