Android: Image cache strategy and memory cache size

后端 未结 3 2111
清歌不尽
清歌不尽 2021-02-05 22:01

I\'m implementing an image cache system for caching downloaded image.

My strategy is based upon two-level cache: Memory-level and disk-level.

My class is very si

3条回答
  •  无人共我
    2021-02-05 22:19

    I am using one-third of the heap for Image cache.

    int memoryInMB = activityManager.getMemoryClass();
    long totalAppHeap = memoryInMB * 1024 * 1024;
    int runtimeCacheLimit =  (int)totalAppHeap/3;
    

    By the way, about soft reference, in Android Soft references do not work as you expect. There is a platform issue that soft references are collected too early, even when there is plenty of memory free.

    Check http://code-gotcha.blogspot.com/2011/09/softreference.html

提交回复
热议问题