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

前端 未结 3 1253
萌比男神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: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.

提交回复
热议问题