Glide preload和into的区别

一、背景

  贝壳2.6.0版本使用Glide preload方法替换了部分显示图片的方式, 在灰度期间发现控件显示了错误的图片或者崩溃问题。

Fatal Exception: java.lang.RuntimeException:Canvas: trying to use a recycled bitmap android.graphics.Bitmap@25e89bf at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1271) at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:257) at android.graphics.Canvas.drawBitmap(Canvas.java:1415) at com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable.draw(GlideBitmapDrawable.java:101)

http://bugly.ke.com/#/2/exceptionList/crash/qaCrashDetail/2/All/1553766449032/1554284849032/All/All/All/e71fba44bfc3a1e14fc63b9f69f2cbc9

 

二、原因分析

    Glide使用activityResources、LruResourceCache、LruBitmapPool等3级内存和文件缓存LazyDiskCacheProvider。

 

  activeResources是个Map, key值(EngineKey)根据10个参数组合生成,value是ResourceWeakReference类型; resource是EngineResource类并实现引用计数。

activeResources.put(key, new ResourceWeakReference(key, resource, getReferenceQueue()));
public void recycle() {
    if (acquired > 0) {
        throw new IllegalStateException("Cannot recycle a resource while it is still acquired");
    }
    if (isRecycled) {
        throw new IllegalStateException("Cannot recycle a resource that has already been recycled");
    }
    isRecycled = true;
    resource.recycle();  //实际上将Bitmap添加到BitmapPool
}
 
/**
 * Increments the number of consumers using the wrapped resource. Must be called on the main thread.
 *
 * <p>
 *     This must be called with a number corresponding to the number of new consumers each time new consumers
 *     begin using the wrapped resource.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值