OOM error when scrolling through gridview

时间:2015-06-25 18:42:20

标签: java android gridview scroll

I am working on an android application with a bunch of clickable gifs. I created a gridview of gifs that is scrollable. The gifs are a gifmovieview from https://github.com/sbakhtiarov/gif-movie-view. The images keep loading into the memory each time I scroll, eventually causing a OOM error after scrolling up and down the list about 6-10 times. How can I fix this? And possibly add smooth scrolling?

2 个答案:

答案 0 :(得分:1)

You're probably keeping all the GIFs in memory. Use an LRUCache to limit the number of GIFs in memory at a time. Smooth scrolling issues are probably due to image decoding. Move that to a separate thread, and show a placeholder image until its done.

答案 1 :(得分:0)

我没有正确回收图像,因此它们无法从内存中删除或重复使用,并且不断添加到彼此之上。

我将convertView!= null更改为convertView == null并将膨胀放入其中。