Android: Random crash issue - android

I am getting a random crash but I am not able to figure out where exactly in the code it is happening.
The app suddenly exits randomly.
This comes around the time when when I am trying to populate a list using ListUI. But not sure of the reason.
The relevent stack trace is mentioned below. Could someone please give me direction, as to what kind of problem could be leading to this issue.
W/InputDispatcher( 188): channel '4171e5b0 com.pv.example.impl/com.pv.example.impl.ExampleActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
E/InputDispatcher( 188): channel '4171e5b0 com.pv.example.impl/com.pv.example.impl.ExampleActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
W/InputDispatcher( 188): Attempted to unregister already unregistered input channel '4171e5b0 com.pv.example.impl/com.pv.example.impl.ExampleActivity (server)'
I/ActivityManager( 188): Process com.pv.example.impl (pid 2419) has died.
W/ActivityManager( 188): Force removing ActivityRecord{41748ee8 com.pv.example.impl/.ExampleActivity}: app died, no saved state
I/WindowManager( 188): WIN DEATH: Window{4171e5b0 com.pv.example.impl/com.pv.example.impl.ExampleActivity paused=false}
I/WindowManager( 188): WINDOW DIED Window{4171e5b0 com.pv.example.impl/com.pv.example.impl.ExampleActivity paused=false}
D/Zygote ( 120): Process 2419 terminated by signal (11)
W/InputManagerService( 188): Got RemoteException sending setActive(false) notification to pid 2419 uid 10058
D/dalvikvm( 1440): GC_FOR_ALLOC freed 6082K, 45% free 19093K/34631K, paused 26ms
D/dalvikvm( 1440): GC_CONCURRENT freed 135K, 40% free 20995K/34631K, paused 3ms+6ms
D/dalvikvm( 1440): GC_FOR_ALLOC freed 1905K, 41% free 20712K/34631K, paused 26ms
D/dalvikvm( 1440): GC_FOR_ALLOC freed 1734K, 40% free 20860K/34631K, paused 23ms
D/dalvikvm( 1440): GC_CONCURRENT freed 1220K, 38% free 21663K/34631K, paused 2ms+4ms
D/dalvikvm( 1440): GC_CONCURRENT freed 2541K, 39% free 21156K/34631K, paused 2ms+10ms
D/dalvikvm( 1440): GC_FOR_ALLOC freed <1K, 39% free 21156K/34631K, paused 21ms
I/dalvikvm-heap( 1440): Grow heap (frag case) to 23.673MB for 3097616-byte allocation
D/dalvikvm( 1440): GC_FOR_ALLOC freed 3K, 31% free 24178K/34631K, paused 53ms
D/dalvikvm( 1440): GC_FOR_ALLOC freed 3784K, 39% free 21247K/34631K, paused 20ms
I/dalvikvm-heap( 1440): Grow heap (frag case) to 23.427MB for 2747152-byte allocation
D/dalvikvm( 1440): GC_CONCURRENT freed <1K, 31% free 23929K/34631K, paused 2ms+5ms
D/dalvikvm( 188): GC_CONCURRENT freed 1399K, 15% free 17287K/20231K, paused 10ms+3ms
D/dalvikvm( 2234): GC_CONCURRENT freed 421K, 5% free 12905K/13447K, paused 3ms+4ms

Related

Logcat doesnot show errors

When I click on the share button of my App, a message shows Unfortunately has stopped. But, this doesn't cause the app to crash. I am able to share my file. The logcat doesn't show any errors. The following is what my logcat displays .
03-28 15:10:23.585 18455-18455/com.example.akn.play_music D/dalvikvm﹕ GC_FOR_ALLOC freed 208K, 2% free 17001K/17240K, paused 28ms, total 28ms
03-28 15:10:25.165 18455-18455/com.example.akn.play_music D/dalvikvm﹕ GC_FOR_ALLOC freed 142K, 2% free 17003K/17312K, paused 11ms, total 12ms
03-28 15:10:25.175 18455-18464/com.example.akn.play_music D/dalvikvm﹕ GC_FOR_ALLOC freed 3K, 2% free 17576K/17892K, paused 11ms, total 11ms

How to avoid GC overhead in Android when using media like Images?

I am creating Image apps which has over 4k images. I dont load images as required rather load when required however if user visits different parts of app which links to different images my app becomes slow and waits for GC to run which makes it bad user experience.
I saw logcat with following messages:
10-08 14:21:26.249: D/dalvikvm(31547): GC_FOR_ALLOC freed 1677K, 13% free 14097K/16124K, paused 29ms, total 29ms
10-08 14:21:26.749: D/dalvikvm(31547): GC_FOR_ALLOC freed 1711K, 13% free 14092K/16124K, paused 28ms, total 28ms
10-08 14:21:27.610: D/dalvikvm(31547): GC_FOR_ALLOC freed 1694K, 13% free 14103K/16124K, paused 29ms, total 29ms
10-08 14:21:29.592: D/dalvikvm(31547): GC_FOR_ALLOC freed 1729K, 13% free 14081K/16124K, paused 32ms, total 32ms
10-08 14:21:30.874: D/dalvikvm(31547): GC_FOR_ALLOC freed 1675K, 13% free 14102K/16124K, paused 30ms, total 30ms
10-08 14:21:32.435: D/dalvikvm(31547): GC_FOR_ALLOC freed 1735K, 13% free 14075K/16124K, paused 33ms, total 33ms
10-08 14:21:34.017: D/dalvikvm(31547): GC_FOR_ALLOC freed 1629K, 13% free 14145K/16124K, paused 28ms, total 29ms
10-08 14:21:35.098: D/dalvikvm(31547): GC_FOR_ALLOC freed 1774K, 13% free 14093K/16124K, paused 29ms, total 29ms
10-08 14:21:36.290: D/dalvikvm(31547): GC_FOR_ALLOC freed 1703K, 13% free 14094K/16124K, paused 29ms, total 29ms
10-08 14:21:37.991: D/dalvikvm(31547): GC_FOR_ALLOC freed 1722K, 13% free 14077K/16124K, paused 27ms, total 28ms
10-08 14:21:39.213: D/dalvikvm(31547): GC_FOR_ALLOC freed 1693K, 13% free 14083K/16124K, paused 28ms, total 28ms
10-08 14:21:41.175: D/dalvikvm(31547): GC_FOR_ALLOC freed 1696K, 13% free 14088K/16124K, paused 28ms, total 28ms
I tried to improve/optimize my code by doing following changes:
Everytime I load app I clear my cached images.
Implemented ViewHolder pattern for ListViews.
Used android:largeHeap="true" attribute in Manifest at Application tag level.
Made classes which are used frequently to do some operations singleton.
But still not able to achieve performance i need.
I used Universal Image Loader Library which has cache mechanism but still its runs GC.
How to avoid GC or what are other optimization techniques.

Why the GC happens so frequent in Android?

I have exit my app, but there is still a backgroud service is running. Whe the GC logs come a log. I will so you the logs beblow. You can see, about 3 logs per second. Is This phenomenon is normal ? My device's memory is enough, and the backgroud service is holding a WebSocket connection.
08-11 10:33:54.456 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2020K, 18% free 10682K/12871K, paused 12ms+6ms, total 44ms
08-11 10:33:54.776 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1985K, 18% free 10676K/12871K, paused 12ms+8ms, total 54ms
08-11 10:33:55.109 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1950K, 18% free 10671K/12871K, paused 12ms+17ms, total 68ms
08-11 10:33:55.459 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2004K, 18% free 10680K/12871K, paused 13ms+8ms, total 62ms
08-11 10:33:55.769 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2010K, 18% free 10680K/12871K, paused 12ms+7ms, total 48ms
08-11 10:33:56.093 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1996K, 18% free 10677K/12871K, paused 12ms+9ms, total 50ms
08-11 10:33:56.416 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2028K, 18% free 10681K/12871K, paused 2ms+8ms, total 37ms
08-11 10:33:56.746 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2031K, 18% free 10682K/12871K, paused 8ms+8ms, total 46ms
08-11 10:33:57.079 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1996K, 18% free 10677K/12871K, paused 12ms+7ms, total 46ms
08-11 10:33:57.429 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2002K, 18% free 10678K/12871K, paused 12ms+19ms, total 59ms
08-11 10:33:57.766 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2003K, 18% free 10679K/12871K, paused 12ms+7ms, total 46ms
08-11 10:33:58.143 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1945K, 18% free 10669K/12871K, paused 12ms+17ms, total 72ms
08-11 10:33:58.473 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2020K, 18% free 10682K/12871K, paused 2ms+6ms, total 41ms
08-11 10:33:58.786 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2013K, 17% free 10690K/12871K, paused 12ms+8ms, total 48ms
08-11 10:33:59.106 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2031K, 18% free 10683K/12871K, paused 12ms+8ms, total 53ms
08-11 10:33:59.443 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2021K, 18% free 10681K/12871K, paused 12ms+8ms, total 48ms
08-11 10:33:59.786 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 2028K, 18% free 10681K/12871K, paused 11ms+7ms, total 44ms
08-11 10:34:00.153 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕ GC_CONCURRENT freed 1997K, 18% free 10677K/12871K, paused 12ms+18ms, total 58ms
Is This phenomenon is normal ?
It depends what you mean by "normal".
If you mean normal for an application with those particular heap dimensions, that amount of heapspace used for long-lived objects, and that rate of allocation ... then the answer is "Yes, it is normal".
Basically, you are running your application with a heap that is (objectively) too small for the work that you are asking it to do. You have roughly 2Mb of free space, and you are allocating objects at roughly 6Gb per second. If you want to reduce the number of GC cycles, you need to do one or more of the following:
Increase the heap size. (I don't know if this is feasible for an Android app ...)
Reduce the "working set" of long-lived objects. Maybe you have a memory leak, lots of large images loaded, or an overly large in-memory cache of ... something.
Reduce the rate at which new objects are being allocated by your application.
The last two require you to track down the source of the memory usage / allocation, and change you code to mitigate the effects. There are tools (memory profilers) that can help with this, but the details will be specific to your application.
Here's how I'd interpret the GC log lines ... by example:
08-11 10:33:54.456 6821-6823/com.tong.iknow:ik_service_v1 E/dalvikvm﹕
GC_CONCURRENT freed 2020K, 18% free 10682K/12871K, paused 12ms+6ms, total 44ms
The "GC_CONCURRENT" collector is being used.
This GC collection cycle reclaimed 2020K bytes.
When the GC cycle completed, 18% of the heap is free, and 10682K out of a total usable heap size of 12871K is in use.
Normal thread activity was paused for two intervals of 12ms and 6ms respectively.
The elapsed time for the GC cycle was 44ms.
Note that the amount of heap freed isn't always exactly the same as the different between total and available ... because for much of the time that the GC is running there are normal threads allocating new objects.

Flood of GC_CONCURRENT freed messages, not my app

I'm getting a flood of GC_CONCURRENT freed messages in LogCat and they are not coming from my own app (I force closed my app to be sure). The memory freed is very consistent (about 1430K) and it occurs about 6 times per second.
How can I troubleshoot this?
It's interfering with my app development because it floods LogCat and forces valuable log statements out of the buffer and also causes LogCat to "jiggle" because the session filter jumps up and down one line each time a GC_CONCURRENT event occurs.
The phone is a Motorola Atrix 2 running Android 2.3.5. I use the phone for development only so it has almost no additional apps than the stock bloatware from AT&T.
11-14 10:50:14.117: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4712K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:14.273: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:14.429: D/dalvikvm(724): GC_CONCURRENT freed 1431K, 52% free 4712K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:14.585: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:14.742: D/dalvikvm(724): GC_CONCURRENT freed 1428K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:14.898: D/dalvikvm(724): GC_CONCURRENT freed 1430K, 52% free 4713K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:15.054: D/dalvikvm(724): GC_CONCURRENT freed 1427K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:15.210: D/dalvikvm(724): GC_CONCURRENT freed 1432K, 52% free 4711K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:15.367: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4712K/9671K, external 2357K/2773K, paused 3ms+2ms
11-14 10:50:15.523: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:15.679: D/dalvikvm(724): GC_CONCURRENT freed 1432K, 52% free 4711K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:15.835: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4712K/9671K, external 2357K/2773K, paused 3ms+2ms
11-14 10:50:15.992: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+2ms
11-14 10:50:16.148: D/dalvikvm(724): GC_CONCURRENT freed 1429K, 52% free 4713K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:16.304: D/dalvikvm(724): GC_CONCURRENT freed 1429K, 52% free 4712K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:16.460: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 2ms+3ms
11-14 10:50:16.617: D/dalvikvm(724): GC_CONCURRENT freed 1430K, 52% free 4713K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:16.773: D/dalvikvm(724): GC_CONCURRENT freed 1429K, 52% free 4712K/9671K, external 2357K/2773K, paused 3ms+3ms
11-14 10:50:16.929: D/dalvikvm(724): GC_CONCURRENT freed 1426K, 52% free 4714K/9671K, external 2357K/2773K, paused 3ms+3ms
The process ID is shown in the message (in the above, it's pid 724). You can use adb shell ps to get the Linux process dump; find the entry for pid 724 to see which app it is.
Alternatively, if you're on a developer device, within Eclipse/ADT/DDMS you can open the "Devices" view and see all processes. Select the app with the matching pid (second column), then open the "Threads" view. This shows all the threads in the app. Look for a thread with high values in the "utime" and "stime" columns. If you double-click on it a few times, you will see snapshots of the stack trace that might suggest what's causing all the GCs.

Why does Android system always call Garbage Collector every time i make a request to web server?

Why does Android system always call garbage collection every time I make a request to web server to get images? Although I did every actions are asynchronous. Calling GC too many times make my app delays when scrolling or fling.
Update: I guess Android system always call GC when you do something request to web server. Here is the log when using the Android default browser. Each time you click on a link GC will be called automatically.
03-08 16:36:19.530: D/dalvikvm(341): GC_FOR_ALLOC freed 2124K, 31% free 10780K/15623K, paused 49ms
03-08 16:36:19.590: D/dalvikvm(341): GC_FOR_ALLOC freed 0K, 20% free 12635K/15623K, paused 49ms
03-08 16:36:19.700: D/dalvikvm(341): GC_CONCURRENT freed 1K, 20% free 12635K/15623K, paused 3ms+4ms
03-08 16:36:22.610: D/dalvikvm(20845): GC_CONCURRENT freed 735K, 10% free 9018K/9991K, paused 2ms+6ms
03-08 16:36:25.620: D/dalvikvm(20845): GC_CONCURRENT freed 1046K, 12% free 8954K/10119K, paused 4ms+3ms
03-08 16:36:27.880: D/dalvikvm(2781): GC_EXPLICIT freed 263K, 7% free 6373K/6791K, paused 2ms+2ms
03-08 16:36:28.950: D/dalvikvm(20845): GC_CONCURRENT freed 884K, 12% free 8946K/10119K, paused 3ms+3ms
03-08 16:36:29.760: D/dalvikvm(20845): GC_CONCURRENT freed 861K, 12% free 8949K/10119K, paused 3ms+3ms
03-08 16:36:31.390: D/dalvikvm(285): GC_EXPLICIT freed 1275K, 38% free 20843K/33223K, paused 17ms+8ms
03-08 16:36:31.510: D/dalvikvm(20845): GC_CONCURRENT freed 810K, 12% free 8946K/10119K, paused 3ms+5ms
03-08 16:36:38.100: D/dalvikvm(20845): GC_CONCURRENT freed 730K, 11% free 9027K/10119K, paused 3ms+6ms
03-08 16:36:40.920: D/dalvikvm(20845): GC_CONCURRENT freed 864K, 12% free 8989K/10119K, paused 2ms+5ms
03-08 16:36:45.780: D/dalvikvm(20845): GC_FOR_ALLOC freed 620K, 12% free 8909K/10119K, paused 41ms
03-08 16:36:48.250: D/dalvikvm(20845): GC_FOR_ALLOC freed 499K, 12% free 9002K/10119K, paused 45ms
03-08 16:36:48.570: D/dalvikvm(20845): GC_FOR_ALLOC freed 225K, 13% free 8899K/10119K, paused 28ms
03-08 16:36:50.670: D/dalvikvm(20845): GC_FOR_ALLOC freed 388K, 12% free 8915K/10119K, paused 34ms
03-08 16:36:52.550: D/dalvikvm(20845): GC_FOR_ALLOC freed 511K, 11% free 9008K/10119K, paused 44ms
03-08 16:36:53.780: D/dalvikvm(20845): GC_FOR_ALLOC freed 273K, 12% free 8909K/10119K, paused 42ms
03-08 16:37:05.070: D/dalvikvm(569): GC_EXPLICIT freed 376K, 12% free 6207K/6983K, paused 2ms+2ms
03-08 16:37:25.550: D/dalvikvm(2549): GC_CONCURRENT freed 337K, 9% free 7198K/7879K, paused 2ms+3ms
03-08 16:37:31.330: D/dalvikvm(2549): GC_EXPLICIT freed 54K, 10% free 7143K/7879K, paused 7ms+2ms
03-08 16:38:45.630: D/dalvikvm(2549): GC_EXPLICIT freed 268K, 10% free 7161K/7879K, paused 7ms+2ms
Android GC is automatic, opaque, non-deterministic. Which means you have nothing can do on it.
Traditionally, this type of GC works like this.
Wait until enough garbages are generated.
If GC engine thinks it's time, it stops your app.
Clear the garbages
Resume your app.
Of course, this sucks for end-use UI and graphics.
So Google added incremental collection. Essentially, this is just doing above procedure more frequently with less garbages. So pause time itself would be short but collection itself happens a lot more frequently.
As a conclusion, garbage collection happens randomly, but very frequently. So it would look happening always for any of operations.
Practically, there's no guaranteed way to avoid GC lag on typical GC systems.

Categories

Resources