8

I'm using Glide to load bitmaps to create a gif.

     for (int i = 0, count = files.size(); i < count; i++) {
         Bitmap img = Glide.with(context)
             .load(files.get(i))
             .asBitmap()
             .centerCrop()
             .into(GIF_EXPORT_SIZE / 2, GIF_EXPORT_SIZE / 2)
             .get();

         // addFrame creates a copy of img, so we can re-use this bitmap
         encoder.addFrame(img);
    }

I was wondering who is responsible for recycling this Bitmap or putting it back in the Glide BitmapPool? There doesn't seem to be a way for Glide to re-use it automatically or by using clear().

I looked at adding the Bitmap back to the Pool directly using something like Glide.get(context).getBitmapPool().put(img) but according to the documentation using the BitmapPool directly can lead to undefined behaviour.

AngusMorton
  • 257
  • 1
  • 9

1 Answers1

0

As per their wiki, Resource re-use: How, you don't have to recycle since Glide does it, but based on the resource count.

When the reference count drops to zero, Glide will recycle the resource and return its contents to any available pools.

Although, you'll have to explicitly call Glide.clear() to decrease the resource count because glide is only able to call Glide.clear() when replacing the image of an already existing target/view. Hope this helps.

PenguinBlues
  • 308
  • 5
  • 15