Android GC - LogCat always showing GC activity

2019-04-30 09:19发布

问题:

when i run my program, logcat shows a lot of activity with GC

like

GC freed 10324 objects/ 510376 bytes in 103 ms
GC freed 10324 objects/ 510376 bytes in 103 ms
GC freed 10324 objects/ 510376 bytes in 103 ms
GC freed 10324 objects/ 510376 bytes in 103 ms
GC freed 10324 objects/ 510376 bytes in 103 ms

with diff in obj, bytes and ms values...

is it because of some bad practice of coding ?

回答1:

If your program dont necessarily needs to dispose of that many objects, then yes. Otherwise, no. If your program needs to run faster or is for example a game that needs to run smooth at all times, then you might try re-using objects to a greater extent.



回答2:

Use the standalone DDMS program and its Allocation Tracker tab to check where/what is being allocated. The DDMS program ships with the sdk. (This is not the same as the ddms tab in Eclipse.)