One line causing lots of garbage collection. String.format with float. Help?

by Marco Nelissen » Tue, 14 Apr 2009 11:40:38 GMT


Sponsored Links
 Don't use String.format(). It creates all kinds of temporary objects
every time you call it.
Instead, create a single StringBuilder and Formatter, and then reuse
those every time you need to format a string.





--~--~---------~--~----~------------~-------~--~----~



One line causing lots of garbage collection. String.format with float. Help?

by Raphael » Tue, 14 Apr 2009 13:04:32 GMT


 First you should try to use StringBuilder, which is the
non-synchronized version of StringBuffer.

Next you could just write:

String price = String.format("$ %.2f",pricef);

which saves you a temporary StringBuffer allocation.

R/





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. GMail Client Source

I'm looking for the source of the GMail Client that comes on the G1.  Is it
available anywhere?

--~--~---------~--~----~------------~-------~--~----~

2. FireWall Packets in Jitter Buffer

Hi,

What does "DecodeFireWallPackets( )" do in pvmf_jitter_buffer_node.cpp
and why is this requried? What is the concept behind using this?

Please answer for my above question.

--~--~---------~--~----~------------~-------~--~----~

3. Turning off SetColorFilter()

4. Tab Issue:

5. GPS + Image EXIF

6. what is the widget platform Android supportted?

7. Compass for android (orientation in 3D space)