First of all I have a simple ListView. Implementing the BaseAdapter and utilizing the ViewHolder pattern I simply have a TextView that on each getView() call sets the text with a different String. Each string has various lengths and it can break into multiple lines.
The excessive garbage collecting occurs when you scroll, it is caused by the StaticLayout that is used inside of the TextView class. It is creating float[]‘s and then the garbage collector collects them and causes a stutter in my ListView‘s scrolling. I came to this conclusion after tracking my scrolling through the Allocation Tracker. Note that excessive is not that it is collection huge chunks of memory but lots of small ones.
Since I am running into this problem even when I simplify my code down to the basics I assume someone has run into this before me. Because this is a system bug and not something I can work around while still using the TextView, what do you suggest I use as a workaround for this bug?
I fixed the behavior, although I still do not understand why it happened. In my
ListViewI was setting the cacheColorHint as#00000000and this was causing problems when combined with my global theme settings ofandroid:windowBackground=@nullandandroid:windowContentOverlay=@null. I don’t understand why it would cause excessive GC nor why simply changing the cacheColorHint to#FFFFFFFFwould effect it, but what the drawing hierarchy of Android does not always follow the most obvious path.