I have an animated game which is generally achieving 25-30 frames per second, though occasionally freezes for a quarter of a second here and there. From looking at assorted posts I guess it is probably doing some garbage collection.
I am using eclipse and am armed with DDMS and the internal profiler – which I haven’t fully got to grips with yet. But as far as I can tell there seem to be very few and infrequent memory allocations going on, and the ones there are seem very small. Also when looking at the list of functions and what percentage of the time they are taking, I can not see anything strange. Mind you I don’t quite know what to looking for – is there a function called DoingGarbageCollectionNow() or similar that I should see on the list? I can’t find anything like it.
EDIT: The little freezes only appear obvious on my Samsung Galaxy Y (Android 2.3.5). On my Google Nexus S (Android 2.3.3), the frame rate is 25 or more throughout.
EDIT: Could the delays even be caused by another app (or OS procedure) running in the background – and if so, how could I tell?
I haven’t wrote on android specifically, but generally you want to examine gc in logging to see it’s behavior and timing.
See this article for android specific gc logging info. http://www.infectentertainment.com/2010/05/28/android-garbage-collection/
Platform agnostic solution may be to look at a parallel gc or other gc types if possible on the platform.
“The concurrent collector introduced in Gingerbread helps[…]” Source: http://developer.android.com/guide/practices/design/performance.html
Better solution still is to avoid instantiation if at all possible by examining creation of objects in loops and eliminating them.