ListView的Item有图片, 当条数很多例如超过1000条,如果不做任何处理, 划动ListView会出现OOM导致应用崩溃。 我们现在都用了三方开源图库框架, 并没有出现OOM, 从而可能忽视了其实现原理, 现在是时候回顾一下了。
先回顾一下ListView的基本知识, ListView继承于AbsListView, AbsListView有个内部类RecycleBin用于复用view,BaseAdpater里getView方法中convertView参数就是从RecycleBin类对象缓存中取的。
注释:The RecycleBin facilitates reuse of views across layouts. The RecycleBin has two levels of storage: ActiveViews and ScrapViews. ActiveViews are those views which were onscreen at the start of a layout. By construction, they are displaying current information. At the end of layout, all views in ActiveViews are demoted to ScrapViews. ScrapViews are old views that could potentially be used by the adapter to avoid allocating