external allocation too large for this process, android - android

in my simple app i am using 6 buttons and setting background with png.
Button btnGadgetmusic = (Button) findViewById(R.id.gadgetmusic);
btnGadgetmusic.setBackgroundResource(R.drawable.btnselectedsong);
minimum size of png is 13.5K and maximum size is 40K. When ever i try to run this app on emulator with version 2.3, i get "external allocation too large for this process" and interestningly if i run on honeycomb or on ICS then there is no problem.
So i am confused what should i do, should i ignore it, if not, do we have some better solution for that.
looking for your reply
EDIT Log File added
I/dalvikvm-heap(4190): Clamp target GC heap from 25.494MB to 24.000MB
D/dalvikvm(4190): GC_FOR_MALLOC freed <1K, 51% free 2647K/5379K, external 18806K/20812K, paused 28ms
D/dalvikvm(4190): GC_EXTERNAL_ALLOC freed <1K, 51% free 2647K/5379K, external 18806K/20812K, paused 49ms
I/dalvikvm-heap(4190): Clamp target GC heap from 25.833MB to 24.000MB
D/dalvikvm(4190): GC_FOR_MALLOC freed 0K, 51% free 2647K/5379K, external 19153K/20812K, paused 25ms
D/dalvikvm(4190): GC_EXTERNAL_ALLOC freed <1K, 51% free 2657K/5379K, external 19153K/20812K, paused 56ms
I/dalvikvm-heap(4190): Clamp target GC heap from 25.852MB to 24.000MB
D/dalvikvm(4190): GC_FOR_MALLOC freed <1K, 51% free 2657K/5379K, external 19162K/20812K, paused 24ms
D/dalvikvm(4190): GC_EXTERNAL_ALLOC freed 4K, 51% free 2671K/5379K, external 19162K/20812K, paused 69ms
I/dalvikvm-heap(4190): Clamp target GC heap from 25.887MB to 24.000MB
D/dalvikvm(4190): GC_FOR_MALLOC freed 0K, 51% free 2671K/5379K, external 19184K/20812K, paused 28ms
W/KeyCharacterMap(4190): No keyboard for id 0
W/KeyCharacterMap(4190): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
W/KeyCharacterMap(4190): No keyboard for id 0
W/KeyCharacterMap(4190): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
I/dalvikvm-heap(4190): Clamp target GC heap from 25.913MB to 24.000MB
D/dalvikvm(4190): GC_CONCURRENT freed 16K, 50% free 2697K/5379K, external 19184K/20812K, paused
3ms+35ms
I/dalvikvm-heap(4190): Clamp target GC heap from 25.942MB to 24.000MB
D/dalvikvm(4190): GC_CONCURRENT freed 13K, 50% free 2727K/5379K, external 19184K/20812K, paused 3ms+3ms
D/dalvikvm(4190): GC_EXTERNAL_ALLOC freed 2K, 50% free 2724K/5379K, external 19184K/20812K, paused 65ms
E/dalvikvm-heap(4190): 20736-byte external allocation too large for this process.
I/dalvikvm-heap(4190): Clamp target GC heap from 25.939MB to 24.000MB
E/GraphicsJNI(4190): VM won't let us allocate 20736 bytes
D/dalvikvm(4190): GC_FOR_MALLOC freed 0K, 50% free 2724K/5379K, external 19184K/20812K, paused 38ms
D/skia(4190): --- decoder->decode returned false
D/AndroidRuntime(4190): Shutting down VM
W/dalvikvm(4190): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(4190): FATAL EXCEPTION: main
E/AndroidRuntime(4190): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Related

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.

Where to store description data for markers to avoid outofmemory errors?

I have 1700 markers with strings holding a description for each marker on the map. I am getting the out of memory error since I am holding so many strings for each markers "click for more info" next screen activity. How can I better hold this data and share it on marker click and not have this memory issue? I am pulling my data from an XML based file.
Here is my error log after crash:
10-07 13:42:55.383: D/dalvikvm(4431): GC_FOR_MALLOC freed 1063K, 57% free 9611K/21959K, external 2506K/2804K, paused 77ms
10-07 13:42:57.109: D/dalvikvm(4431): GC_FOR_MALLOC freed 1580K, 56% free 9821K/21959K, external 2551K/2804K, paused 114ms
10-07 13:42:57.320: D/dalvikvm(4431): GC_FOR_MALLOC freed 427K, 55% free 10016K/21959K, external 2365K/2804K, paused 97ms
10-07 13:42:57.656: D/dalvikvm(4431): GC_FOR_MALLOC freed 168K, 54% free 10142K/21959K, external 2365K/2804K, paused 166ms
10-07 13:42:57.804: D/dalvikvm(4431): GC_FOR_MALLOC freed 118K, 54% free 10218K/21959K, external 2365K/2804K, paused 85ms
10-07 13:42:57.922: D/dalvikvm(4431): GC_FOR_MALLOC freed 47K, 54% free 10320K/21959K, external 2365K/2804K, paused 71ms
10-07 13:42:58.031: D/dalvikvm(4431): GC_FOR_MALLOC freed 119K, 54% free 10297K/21959K, external 2365K/2804K, paused 70ms
10-07 13:42:58.148: D/dalvikvm(4431): GC_FOR_MALLOC freed 51K, 53% free 10342K/21959K, external 2365K/2804K, paused 69ms
10-07 13:42:58.148: I/dalvikvm-heap(4431): Grow heap (frag case) to 14.855MB for 33642-byte allocation
10-07 13:42:58.226: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10375K/22023K, external 2365K/2804K, paused 77ms
10-07 13:42:58.328: D/dalvikvm(4431): GC_FOR_MALLOC freed 83K, 54% free 10343K/22023K, external 2365K/2804K, paused 73ms
10-07 13:42:58.336: I/dalvikvm-heap(4431): Grow heap (frag case) to 14.863MB for 40183-byte allocation
10-07 13:42:58.406: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 53% free 10383K/22087K, external 2365K/2804K, paused 72ms
10-07 13:42:58.476: D/dalvikvm(4431): GC_FOR_MALLOC freed 42K, 54% free 10379K/22087K, external 2365K/2804K, paused 71ms
10-07 13:42:58.609: D/dalvikvm(4431): GC_FOR_MALLOC freed 62K, 53% free 10381K/22087K, external 2365K/2804K, paused 78ms
10-07 13:42:58.750: D/dalvikvm(4431): GC_FOR_MALLOC freed 44K, 53% free 10421K/22087K, external 2365K/2804K, paused 79ms
10-07 13:42:58.758: I/dalvikvm-heap(4431): Grow heap (frag case) to 15.005MB for 111024-byte allocation
10-07 13:42:58.844: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10529K/22215K, external 2365K/2804K, paused 75ms
10-07 13:42:58.961: D/dalvikvm(4431): GC_EXTERNAL_ALLOC freed 10K, 53% free 10528K/22215K, external 2365K/2804K, paused 111ms
10-07 13:42:58.992: E/dalvikvm-heap(4431): 32-byte external allocation too large for this process.
10-07 13:42:58.992: W/OSMemory(4431): External allocation of 32 bytes was rejected
10-07 13:42:59.070: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 53% free 10528K/22215K, external 2365K/2804K, paused 68ms
10-07 13:42:59.187: D/dalvikvm(4431): GC_FOR_MALLOC freed 32K, 53% free 10535K/22215K, external 2365K/2804K, paused 69ms
10-07 13:42:59.187: I/dalvikvm-heap(4431): Forcing collection of SoftReferences for 40194-byte allocation
10-07 13:42:59.250: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10534K/22215K, external 2365K/2804K, paused 67ms
10-07 13:42:59.258: E/dalvikvm-heap(4431): Out of memory on a 40194-byte allocation.
10-07 13:42:59.258: I/dalvikvm(4431): "its_ter" prio=5 tid=13 RUNNABLE
10-07 13:42:59.258: I/dalvikvm(4431): | group="main" sCount=0 dsCount=0 obj=0x4058b398 self=0xfcfe0
10-07 13:42:59.258: I/dalvikvm(4431): | sysTid=4443 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1036568
10-07 13:42:59.258: I/dalvikvm(4431): at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:~122)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.m.y.a((null):-1)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.k.d.a((null):-1)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.k.g.handleMessage((null):-1)
10-07 13:42:59.265: I/dalvikvm(4431): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 13:42:59.281: I/dalvikvm(4431): at android.os.Looper.loop(Looper.java:130)
10-07 13:42:59.281: I/dalvikvm(4431): at maps.k.d.c((null):-1)
10-07 13:42:59.281: I/dalvikvm(4431): at maps.ao.b.run((null):-1)
10-07 13:42:59.289: W/System.err(4431): OutOfMemory
10-07 13:42:59.429: D/dalvikvm(4431): GC_EXPLICIT freed 32K, 53% free 10567K/22215K, external 2365K/2804K, paused 128ms
10-07 13:42:59.539: D/dalvikvm(4431): GC_FOR_MALLOC freed 435K, 54% free 10235K/22215K, external 2365K/2804K, paused 75ms
10-07 13:42:59.539: I/dalvikvm-heap(4431): Forcing collection of SoftReferences for 119952-byte allocation
10-07 13:42:59.633: D/dalvikvm(4431): GC_FOR_MALLOC freed 111K, 55% free 10123K/22215K, external 2365K/2804K, paused 97ms
10-07 13:42:59.734: D/dalvikvm(4431): GC_EXTERNAL_ALLOC freed 2K, 54% free 10241K/22215K, external 2365K/2804K, paused 85ms
10-07 13:42:59.765: E/dalvikvm-heap(4431): 32-byte external allocation too large for this process.
10-07 13:42:59.765: W/OSMemory(4431): External allocation of 32 bytes was rejected
10-07 13:42:59.844: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 54% free 10241K/22215K, external 2365K/2804K, paused 69ms
10-07 13:42:59.890: W/dalvikvm(4431): threadid=13: thread exiting with uncaught exception (group=0x40015560)
10-07 13:42:59.914: W/dalvikvm(4431): threadid=20: thread exiting with uncaught exception (group=0x40015560)
10-07 13:42:59.922: I/Process(4431): Sending signal. PID: 4431 SIG: 9
I am posting them on the map like so:
BitmapDescriptor icon = BitmapDescriptorFactory
.fromResource(R.drawable.snotel_marker);
int nsize = visibleMarkers.size();
for (int i = 0; i < nsize; i++) {
MapMarkers marks = new MapMarkers();
String title = visibleMarkers.valueAt(i).getTitle();
String desc = visibleMarkers.valueAt(i).getDesc();
Float latitude = visibleMarkers.valueAt(i).getLat();
Float longitude = visibleMarkers.valueAt(i).getLon();
m = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title).icon(icon));
marks.setTitle(title);
marks.setDesc(desc);
m.setData(marks);
On Info Window Click the next activity is populated like so:
getSupportActionBar().setTitle(extras.getString("name"));
webview.loadDataWithBaseURL(null, extras.getString("description"),
"text/html", "utf-8", null);
The app runs fine on my GNex, but on my old Droid, it populates the map, then after clicking on 3 or 4 markers and moving the map around I get the out of memory error. Any other output I can share to try and figure this out?
EDIT heap dump from MAT - String is the issue according to this:
Problem Suspect 1
9,566 instances of "java.lang.String", loaded by "<system class loader>" occupy 2,299,848 (34.18%) bytes.
Keywords
java.lang.String
Details »
Problem Suspect 2
3,381 instances of "java.lang.Class", loaded by "<system class loader>" occupy 960,088 (14.27%) bytes.
Biggest instances:
•class android.text.Html$HtmlParser # 0x4018c9d0 - 126,632 (1.88%) bytes.
Keywords
java.lang.Class
Details »

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