Out of memory cache error when accessing inside the app

后端 未结 2 632
野趣味
野趣味 2020-12-22 08:37

I\'ve searched a lot but I did not understand where to is my error. First in my app I am getting images from the web if there is no net I am getting them from created databa

2条回答
  •  时光取名叫无心
    2020-12-22 09:08

    memory management is a pretty extensive and advanced topic but I'll post a very important tip all in capital letters:

    DO NOT USE MAP !!!

    the map is keeping references to the imageview (which keeps the activity context) and the bitmaps for ever and it's one of the main reasons you have those memory losses. Further on the reference to context is keep your whole activity in memory, for ever. All very bad ideas.

    You'll use a LruCache (available on the compatibility library) to cache the bitmaps, and let only the activity keep reference to the imageviews (either static from the XML or dynamically using an adapter)

    here is a Google IO video http://www.youtube.com/watch?v=gbQb1PVjfqM where the guys from Google themselves are showing some best practices around this area, on the 4min mark they show the usage of the LruCache.

提交回复
热议问题