Request: offer a flag to avoid auto-recycling of a Bitmap instance · Issue #5506 · bumptech/glide · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use this simple call to get some Bitmap that I want to use right away in the current thread (and maybe even use it somewhere else), and as I don't want the cache to work here (I replace the same file with a different file later), I also disable it:
val bitmap =Glide.with(applicationContext).asBitmap()
.load(file)
.apply(RequestOptions.centerCropTransform().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE))
.submit(photoThumbnailSize, photoThumbnailSize).get()
//use the bitmap right here (not into ImageView)
I've noticed that I got some crashes reported here via Crashlytics, saying the bitmap is recycled, so I can't use it...
The reason is that there is no reference anymore to the FutureTask, so Glide is auto-recycling the Bitmap:
I might be able to overcome this by copying the result bitmap while also having a reference to the task:
val futureTarget: FutureTarget<Bitmap> = Glide.with(applicationContext)
.asBitmap()
.load(file)
.apply(RequestOptions.centerCropTransform().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE))
.submit(photoThumbnailSize, photoThumbnailSize)
val bitmap: Bitmap? = futureTarget.get()
//copy the bitmap to a new instance here, instead of using it wherever I wish...
But this is a bad workaround as it uses double the memory, and even here I'm not sure it will work. Maybe it will cause GC before I copy the Bitmap as there is no use of the "futureTarget" anymore (optimization by the GC), and recycle the Bitmap?
Anyway, please offer a way to overcome this, to let me do the decoding&downsampling operation without the danger of my bitmap being recycled by Glide.
The text was updated successfully, but these errors were encountered:
AndroidDeveloperLB
changed the title
Bug: Glide sometimes recycles a Bitmap instance that I've created from it right before I'm about to use it
Request: offer a flag to avoid auto-recycling of a Bitmap instance
May 4, 2025
It seems what I suggested as workarounds don't really work.
So now I wonder if there is any way to use Glide just for decoding with extra functionality, or I have to use real targets and have a hard reference to them all the time...
And still, the request is to be able to avoid this auto-recycling easily, without workarounds...
BTW, the docs about recycling a Bitmap says:
This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.
I use this simple call to get some Bitmap that I want to use right away in the current thread (and maybe even use it somewhere else), and as I don't want the cache to work here (I replace the same file with a different file later), I also disable it:
I've noticed that I got some crashes reported here via Crashlytics, saying the bitmap is recycled, so I can't use it...
The reason is that there is no reference anymore to the FutureTask, so Glide is auto-recycling the Bitmap:
https://bumptech.github.io/glide/doc/resourcereuse.html#reference-counting
I might be able to overcome this by copying the result bitmap while also having a reference to the task:
But this is a bad workaround as it uses double the memory, and even here I'm not sure it will work. Maybe it will cause GC before I copy the Bitmap as there is no use of the "futureTarget" anymore (optimization by the GC), and recycle the Bitmap?
Anyway, please offer a way to overcome this, to let me do the decoding&downsampling operation without the danger of my bitmap being recycled by Glide.
The text was updated successfully, but these errors were encountered: