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. Database Leak in LogCat - SQLiteDatabase, Cursor, Lifecycle

In LogCat I keep getting Database Leak found.  The 'tag' is Database
and the 'message' is Leak found.  And its followed by many lines of
red in LogCat.

I'm using an SQLiteDatabase and I access it from two Activities and
one Service.  In the Service I explicitly close both the cursor and
then the database since I can't use startManagingCursor in there.  In
both Activities I open the database in both onCreate and onResume and
close in onPause.  In one Activity I also use a cursor with
startManagingCursor to manage that for me.

So what is going on here?  My app seems to be working almost all the
time but the "Database Leak found" is very disconcerting.  Thanks in
advance.
--~--~---------~--~----~------------~-------~--~----~

2. Porting Android to AT91SAM9261

Hi guys!

I'm trying to run Android on an Atmel AT91SAM9261. After compiling the
kernel and building Android with the Google Toolchain, I created a
jffs2 image and flashed it onto the CPU.

Then I tried to boot with
"root=/dev/mtdblock0 rw rootfstype=jffs2 console=ttyS0,115200 ip=off
lep9261-bl.brightness=90 noinitrd mem=32M init=/init"
but this stops after
"VFS: Mounted root (jffs2 filesystem).
Freeing init memory: 500K"
As this is the point where init should start, I tried to boot with
init=/system/bin/sh, which gives me a small shell. If I try to run /
init from in there I just get a Segmentation Fault.

strace /init is giving a lot of output like:
"mkdir("/dev/block/", 0755)              = -1 EEXIST (File exists)
mknod("/dev/block/ram3", S_IFBLK|0600, makedev(1, 3)) = 0
chown32("/dev/block/ram3", 0, 0)        = 0
SYS_292(0x4, 0xbebd083a, 0x400, 0, 0)   = -1 EAGAIN (Try again)
umovestr: I/O erro")                   = 344
semtimedop(0x6, 0x2912b, 0x24000, 0, 0x7) = 7
semtimedop(0x7, 0x1c5d0, 0x20001, 0, 0x2a070) = -1 ENOENT (No such
file or directory)
umovestr: I/O erro")                   = 48
umovestr: I/O erro")                   = 0
close(7)                                = 0
semtimedop(0x6, 0x2914b, 0x24000, 0, 0x2a070) = 7
semtimedop(0x7, 0x1c5d0, 0x20001, 0, 0x2a070) = -1 ENOENT (No such
file or directory)
umovestr: I/O erro")                   = 48
umovestr: I/O erro")                   = 0
close(7)                                = 0
umovestr: I/O erro")                   = 0
close(6)                                = 0
semtimedop(0x5, 0x28023, 0x24000, 0, 0x28ff0) = 6
semtimedop(0x6, 0x1c5d0, 0x20001, 0, 0x28ff0) = 7
write(7, "add\n", 4)                    = 4
close(7)                                = 0
SYS_292(0x4, 0xbebd083a, 0x400, 0, 0)   = 104
mkdir("/dev/block/", 0755)              = -1 EEXIST (File exists)
mknod("/dev/block/ram4", S_IFBLK|0600, makedev(1, 4)) = 0
chown32("/dev/block/ram4", 0, 0)        = 0
SYS_292(0x4, 0xbebd083a, 0x400, 0, 0)   = -1 EAGAIN (Try again)
umovestr: I/O erro")                   = 344
semtimedop(0x6, 0x2912b, 0x24000, 0, 0x7) = 7
semtimedop(0x7, 0x1c5d0, 0x20001, 0, 0x2a070) = -1 ENOENT (No such
file or directory)
umovestr: I/O erro")                   = 48
umovestr: I/O erro")                   = 0
close(7)                                = 0
semtimedop(0x6, 0x2914b, 0x24000, 0, 0x2a070) = 7
semtimedop(0x7, 0x1c5d0, 0x20001, 0, 0x2a070) = -1 ENOENT (No such
file or directory)
umovestr: I/O erro")                   = 48
umovestr: I/O erro")                   = 0
close(7)                                = 0
umovestr: I/O erro")                   = 0
close(6)                                = 0
semtimedop(0x5, 0x2803b, 0x24000, 0, 0x28ff0) = 6
semtimedop(0x6, 0x1c5d0, 0x20001, 0, 0x28ff0) = 7
write(7, "add\n", 4)                    = 4
close(7)                                = 0
SYS_292(0x4, 0xbebd083a, 0x400, 0, 0)   = 104
mkdir("/dev/block/", 0755)              = -1 EEXIST (File exists)
mknod("/dev/block/ram5", S_IFBLK|0600, makedev(1, 5)) = 0
chown32("/dev/block/ram5", 0, 0)        = 0
SYS_292(0x4, 0xbebd083a, 0x400, 0, 0)   = -1 EAGAIN (Try again)
umovestr: I/O erro")                   = 344
semtimedop(0x6, 0x2912b, 0x24000, 0, 0x7) = 7
semtimedop(0x7, 0x1c5d0, 0x20001, 0, 0x2a070) = -1 ENOENT (No such
file or directory)
umovestr: I/O erro")"

Has anybody got ideas where the problem is? Seems like wrong
executable format or something like this to me. I also tried to
compile with another toolchain (codesourcery), but still having the
same problem.


Regards,

Thomas Roth
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. why I can not get log whose logtag is "GSM"

4. Regarding Android init process

5. Runescape

6. The code in android which draw a rectangle surrounding an anchor in Webkit

7. Android-X86 upon ThinkPad Series