ListView memory leak: not able to recycle list elements (ImageView + Bitmap)
I have a ListView that uses an adapter to populate a list of ImageViews. I'm following the standard practice of:
a) inflating a new view only if convertView is null, and
b) using a viewHolder to avoid calling findViewById() if convertView is not null
I'm also using an AsyncTask to populate the ImageViews from a database (or from disk cache or LRU memory cache, if possible).
Everything works fine for awhile (ie, images populate in the list with smooth scrolling), but I have a leak that gives an OOM error after about 70 x 1.4M images have been loaded.
My understanding is that ListViews are recycled when getView() returns a non-null convertView, so I shouldn't see a memory build up like this. In my case, the app's memory use grows every time an ImageView gets assigned a Bitmap. And in fact, the Activity holds onto this memory even after I've cleared the underlying list via list.clear(), and zeroed out the adapter via adapter.notifyDataSetInvalidated() - both in the onStop() function.
The MAT tool shows stranded Bitmaps and stranded ImageViews (approximately 1-to-1 with the images loaded), but I don't know what's holding a reference that would prevent garbage collection of the old views.
I'd appreciate any suggestions for how to track down this leak. Thanks!
链接地址: http://www.djcxy.com/p/67340.html