Android DDMS and allocation tracking - Identifying what is causing the GC to trigger and why
Good afternoon.
I have been making a small openGL based app for android that loops at the normal 60 fps and does various wondrous things.
I have been keeping an eye on my frame rate and trying to optimise where possible as I am going along. I recently noticed that whilst my program is running sometimes there will be a slight pause. I immediatly suspected that it might be the Garbage Collector running and looking in LogCat there were a few suspect GC's appearing around the times of the dips in fps.
However I am unsure if it is my app that is causing th开发者_运维百科e collects.
So these are my questions about the GC:
1) When I get logging from LogCat it contains a PID (process id?) and here is an example of a typical GC i receive:
12-14 14:52:40.647: DEBUG/dalvikvm(492): GC_EXPLICIT freed 3831 objects / 203576 bytes in 32ms
The 492 is the PID. Is this PID going to be of the process that performs the GC? Or is it a process running on the phone that is also needing a GC?
For example from the same session here is a log from my app using Log.debug:
12-14 13:50:42.717: DEBUG/Curve(2298): LIFECYCLE - OnStart
The PID for my app is not 492, it is 2298. Does this mean the GC was not due to my app?
Using the allocation tracker I have very few allocations occuring. A few lines of logging causing some strings to be generated and the occasional Rect being generated on a user press (I have fixed this so it will only be allocated once now...) So I cannot see how my app itself will be generating the need for GC's.
2) If it is not my app allocating away and is simply some other process that is eating into memory happily should it affect my app at all?
3) Could the very fact I am using the ddms be causing GC's?
4) When I look in to the allocation tracker there are some entries which do not come from any code that I am running / going through myself. One of which was related to thread stats, could this be the ddms?
Sorry if this is really several questions but it is all related to really whether the GC logs I see in my Logcat are actually from my application or not.
Bearing in mind that at the moment my phone is sat not running my app and I am still getting small GC's 5 - 15 seconds. These normally run for 33ms and seems quite small amounts of memory. So I guess this means they are not due to me. - Again basically about the PID and what that shows.
You are correct on 1). Only a subset of the GC logs ing Logcat belong to your app, and those have your app's pid.
Most likely the hiccups are due to background services requesting small allocations. I'd suggest you apply a low-pass filter to the delta time between frames in your game or cap the maximum FPS for an overall smoother experience. Even on iOS it's extremelly difficult to have your game running at 60FPS without eventual hiccups.
精彩评论