Android GridView garbage collecting (GC_EXTERNAL_ALLOC) <1K overzealously, causing very choppy UI

前端 未结 3 1254
萌比男神i
萌比男神i 2021-01-31 05:18

I have been looking at this for a long time and finally decided to post - my 2xN GridView, which consists of cells with a single image and piece of text is very choppy a lot of

相关标签:
3条回答
  • 2021-01-31 06:02

    Using SimpleCursorAdapter with a custom 2 line ListView layout being used in a ListActivity, no images just text and I have CacheColorHint - #00000000. before I begin I will say that a quick fix is removing cachecolorhint but I need it so it is not a fix to the GC so....

    I have had issues with this same problem now and in the past however this throws a curve ball in it... I have two applications which are essentially mirror images of each other. One will run just fine with no rampant Garbage Collection in the logcat and it scrolls beautifully, The other does not work so well and nothing, no copy and pasting of code can fix it from one to the other.

    ALSO!...Sometimes in the app that is not working so well, I can get it to work when I resort the list from a query and use a slightly different layout for the list view. Don't jump to conclusions though because if I navigate away and come back, the same sorted query using simple cursor adapter on a custom 2 line list item layout will cause the GC again. In other words sometimes it will simply work correctly, and other times it won't. Mind you, I have "scrollingCache" left as the default on both apps and as I said they are copies of each other.

    A while back I encountered this and was able to resolve it somehow and it had nothing to do with ScrollingCache. Rather it had to do with my build compiling against some old version of Android (I think) My memory is not 100% certain of this but I swear the fix was related to a build/compiler issue. I will post something if I remember what fixed it. I use Surround so I am searching for changes. I hope this made sense

    0 讨论(0)
  • 2021-01-31 06:04

    After trying out more things at random, I believe I was able to solve the issue by setting GridView's scrollingCache to false in the XML. It's now buttery smooth.

    http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:scrollingCache

    So, a setting that is supposed to make the GridView use more memory and draw from cache faster in fact causes just the opposite due to GC by making it choppy. Turning the cache off uses less memory and isn't choppy anymore.

    This is a win-win in my book, and I hope it helps someone in the future (ಠ_ಠ Google).

    Edit: Just tried it on a decently-performing ListView, which occasionally would call GC_EXTERNAL_ALLOC to free small amounts of memory. Removing it from a ListView got rid of many tiny GC_EXTERNAL_ALLOC calls altogether and only an occasional larger GC_CONCURRENT call is left. Now a decently-performing ListView is a great-performing ListView. So scrollingCache seems to be something to avoid in any list and shouldn't be enabled by default IMO.

    0 讨论(0)
  • 2021-01-31 06:21

    This is also a problem with ListViews, and the frequent stop-the-world garbage collection causes a poor end-user experience and leads the user to blame Android for choppy UI performance. However, this problem can also be solved in the same way by setting the scrollingCache to false.

    0 讨论(0)
提交回复
热议问题