简体   繁体   中英

Crash on using Glide library

Loading different size of images into ImageView using Glide Library. But not sure why glide fails to handle the memory consumption, recycle and reuse it.

Gradle:

api 'com.github.bumptech.glide:glide:4.3.0'

Usage:

@BindingAdapter({"imageUrl"})
public static void imageUrl(ImageView view, String imageUrl) {
    try {
        if (imageUrl!=null) {
            Glide.with(view.getContext()).load(imageUrl).into(view);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Crash Log:

 04-23 13:19:34.390 4758-4758/xx.xx.xxxE/AndroidRuntime: FATAL EXCEPTION: main
    Process: xxx.xx.xxxx, PID: 4758
    java.lang.RuntimeException: Unable to destroy activity {xx.xx.xx/x.xx.xx.xxx.xxxxActivity}: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@e212eb2[12x12] ARGB_8888
        at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4603)
        at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4621)
        at android.app.ActivityThread.-wrap5(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1757)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.lang.IllegalStateException: Cannot obtain size for recycled Bitmap: android.graphics.Bitmap@e212eb2[12x12] ARGB_8888
        at com.bumptech.glide.util.Util.getBitmapByteSize(Util.java:74)
        at com.bumptech.glide.load.engine.bitmap_recycle.SizeConfigStrategy.removeLast(SizeConfigStrategy.java:97)
        at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.trimToSize(LruBitmapPool.java:221)
        at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.evict(LruBitmapPool.java:116)
        at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.put(LruBitmapPool.java:112)
        at com.bumptech.glide.load.resource.bitmap.LazyBitmapDrawableResource.recycle(LazyBitmapDrawableResource.java:57)
        at com.bumptech.glide.load.engine.EngineResource.recycle(EngineResource.java:63)
        at com.bumptech.glide.load.engine.ResourceRecycler.recycle(ResourceRecycler.java:28)
        at com.bumptech.glide.load.engine.Engine.onResourceRemoved(Engine.java:326)
        at com.bumptech.glide.load.engine.cache.LruResourceCache.onItemEvicted(LruResourceCache.java:31)
        at com.bumptech.glide.load.engine.cache.LruResourceCache.onItemEvicted(LruResourceCache.java:11)
        at com.bumptech.glide.util.LruCache.trimToSize(LruCache.java:175)
        at com.bumptech.glide.util.LruCache.evict(LruCache.java:180)
        at com.bumptech.glide.util.LruCache.put(LruCache.java:135)
        at com.bumptech.glide.load.engine.cache.LruResourceCache.put(LruResourceCache.java:11)
        at com.bumptech.glide.load.engine.Engine.onResourceReleased(Engine.java:334)
        at com.bumptech.glide.load.engine.EngineResource.release(EngineResource.java:101)
        at com.bumptech.glide.load.engine.Engine.release(Engine.java:292)
        at com.bumptech.glide.request.SingleRequest.releaseResource(SingleRequest.java:337)
        at com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:316)
        at com.bumptech.glide.manager.RequestTracker.clearRemoveAndRecycle(RequestTracker.java:62)
        at com.bumptech.glide.RequestManager.untrack(RequestManager.java:462)
        at com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:449)
        at com.bumptech.glide.RequestManager.clear(RequestManager.java:437)
        at com.bumptech.glide.RequestManager.onDestroy(RequestManager.java:290)
        at com.bumptech.glide.manager.ActivityFragmentLifecycle.onDestroy(ActivityFragmentLifecycle.java:64)
        at com.bumptech.glide.manager.SupportRequestManagerFragment.onDestroy(SupportRequestManagerFragment.java:187)
        at android.support.v4.app.Fragment.performDestroy(Fragment.java:2516)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1557)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3227)
        at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:3218)
        at android.support.v4.app.FragmentController.dispatchDestroy(FragmentController.java:262)
    04-23 13:19:34.391 4758-4758/xx.xxx.xxxE/AndroidRuntime:     at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:362)
            at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:209)
            at android.app.Activity.performDestroy(Activity.java:7462)
            at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1255)
            at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4590)
                ... 9 more

*used "xxx" for package name ignore it.

Try withRequestOptions & Upgrade version.

RequestOptions requestOptions = new RequestOptions();
                 Glide.with(getContext())
                    .setDefaultRequestOptions(requestOptions)
                    .load(imageUrl)
                    .into(view);

build.gradle should be

 dependencies {
  implementation 'com.github.bumptech.glide:glide:4.6.1'
 }

You can read Cannot obtain size for recycled Bitmap (LazyBitmapDrawableResource) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM