Android(安卓)软引用内存缓存图片
16lz
2021-01-26
1,实现效果
-
内存不足的时候使用Map集合强引用 ,不容易被释放,我使用SoftReference
2,实现逻辑
引用
【1】使用软引用进行,叫系统内存不足时能快点进行释放 ,软引用在版本更改后会被很快的释放
package com.utils.pic;import android.graphics.Bitmap;import android.support.v4.util.LruCache;public class MemCacheUtils { // SoftReference<> 软引用 // WeakReference 弱引用 // PhantomReference 虚引用 // 存的是bitmap对应的软引用 HashMap> mMaps;// 存图片 public MemCacheUtils() { super(); mMaps = new HashMap>(); } public void setCache(String url, Bitmap bimBitmap) { SoftReference softReference = new SoftReference(bimBitmap); } public Bitmap getCache(String url) { Bitmap bitmap = null; SoftReference softReference = mMaps.get(url); if (softReference != null) { // 取出bitmap bitmap = softReference.get(); } return bitmap; }}
更多相关文章
- Android面试题总结(六)Android源码篇
- android http3 下篇
- android中.this与.class使用的区别
- Android(安卓)内存泄漏检查工具LeakCanary源碼浅析
- android 读书笔记 1
- android资源别名
- Android(安卓)NDK之 ----- Java 方法映射到C中的签名
- Android(安卓)点亮屏幕
- (笔记)Android(安卓)Gradle applicationId