question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canvas: trying to use a recycled bitmap android.graphics.Bitmap

See original GitHub issue

There is an issue

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@f4db2e9
                                                                                         at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1270)
                                                                                         at android.graphics.Canvas.drawBitmap(Canvas.java:1404)
                                                                                         at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:544)
                                                                                         at com.squareup.picasso.PicassoDrawable.draw(PicassoDrawable.java:96)
                                                                                         at android.widget.ImageView.onDraw(ImageView.java:1246)
                                                                                         at android.view.View.draw(View.java:16184)
                                                                                         at android.view.View.updateDisplayListIfDirty(View.java:15180)
                                                                                         at android.view.View.draw(View.java:15954)
                                                                                         at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                         at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                         at android.view.View.updateDisplayListIfDirty(View.java:15175)
                                                                                         at android.view.View.draw(View.java:15954)
                                                                                         at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                         at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                         at android.widget.AbsListView.dispatchDraw(AbsListView.java:2615)
                                                                                         at android.view.View.draw(View.java:16187)
                                                                                         at android.widget.AbsListView.draw(AbsListView.java:4166)

ListAdapter getView code

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;

        if (rowView == null) {
            rowView = inflater.inflate(R.layout.list_item_coupons, null);
        }

        ImageView image = (ImageView) rowView.findViewById(R.id.image);
        String url = BuildConfig.imagesUrl + mList.get(position).getImage();
       
            Picasso.with(context)
                    .load(url)
                    .into(image);
return rowView;
       }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Qamar4Pcommented, Mar 27, 2017
W/Bitmap: Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!
D/Picasso: Main        completed    [R116] from MEMORY
D/AndroidRuntime: Shutting down VM
D/Picasso: Hunter      decoded      [R108]+1978ms 
D/Picasso: Main        created      [R118] Request{https://abc.xyz/uploads/1471380484.0247.png}
W/GAv4: syncDispatchLocalHits timed out: java.util.concurrent.TimeoutException
        --------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main

For now I solve issue with CustomImageView

@Override
    protected void onDraw(Canvas canvas) {
        if(getDrawable() instanceof BitmapDrawable){
            if (((BitmapDrawable)getDrawable()).getBitmap().isRecycled()) {
                return;
            }
        }

        super.onDraw(canvas);
    }

and to reduce requests. I change in adapter getView

if(holder.position != position) {
            ListItem item = items.get(position);
            holder.bind(item);
            holder.position = position;
        }
1reaction
foxcode7commented, Jan 23, 2018

you can try set memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Canvas: trying to use a recycled bitmap android.graphics ...
In my case error was caused because I changed visibility from gone to visible (or vice versa) of an element of the layout....
Read more >
Canvas: trying to use a recycled bitmap, Glide 4.9.0 #3594
I have one place (in BitmapTransformation for glide's .transform() ) in application where I do bitmap.recycle() - can it be the problem?
Read more >
Android : Canvas: trying to use a recycled bitmap ... - YouTube
Android : Canvas : trying to use a recycled bitmap android.graphics.Bitmap in Android [ Beautify Your Computer ...
Read more >
java.lang.RuntimeException: Canvas: trying to use a recycled ...
RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41371280 at android.graphics.Canvas.throwIfRecycled(Canvas.java:1038) at ...
Read more >
Canvas: trying to use a recycled bitmap android.graphics
复现很容易:写一个Bitmap,调用Bitmap的recycle()方法将其回收掉,再设置给ImageView。 1. 2. mBitmap.recycle();. mImageView.setImageBitmap( ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found