0

I have a list of objects the user can create and delete on runtime and each object is assigned an icon. When I do multiple add/delete operations on these objects at some point I get the following exception.

java.lang.IllegalStateException: Cannot recycle a resource that has already been recycled
at com.bumptech.glide.load.engine.EngineResource.recycle(EngineResource.java:71)
at com.bumptech.glide.load.engine.ResourceRecycler$ResourceRecyclerCallback.handleMessage(ResourceRecycler.java:37)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:135)

I perform no recycle operations on my own and I do not make any calls to Glide bitmap pool. My custom Glide model is the following class

public class MyGlideInput {

    private String packageName, apkFilePath, iconResName;

    public MyGlideInput() {
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if(obj == null){
            return false;
        }
        if(!(obj instanceof MyGlideInput)){
            return false;
        }
        MyGlideInput input = (MyGlideInput) obj;
        return stringsEqual(packageName, input.packageName ) && stringsEqual(apkFilePath, input.apkFilePath)
                && stringsEqual(iconResName, input.iconResName);
    }

    @Override
    public int hashCode() {
        return (apkFilePath+packageName+iconResName+"").hashCode();
    }

    public boolean stringsEqual(String a, String b){
        return a != null && a.equals(b);
    }

}

on RecyclerView adapter class in bindViewHolder I do:

GlideInput glideInput = new GlideInput().setDrawableResName(iconResName);
GlideApp.with(img).load(glideInput).dontAnimate().error(R.drawable.warning).into(img);

Any suggestions?

Anonymous
  • 4,470
  • 3
  • 36
  • 67

1 Answers1

0

From what I have seen until now, this error appears mostly because of transformations if you have any. I had some recycling in transform method even though it's stated that developers should not do it by themselves in their custom transformations. Also, you should be really careful in RecycleView.

Can you provide us with more of code, e.g. some transformations that you use or whatever you think it can have some bad impact?

zeroDivider
  • 1,050
  • 13
  • 29