bumptech / bumptech/glide

If the same URL is read into the View, the RequestListener will be reused as stale.

Open
#5,337 3 comments 10 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

## As of Glide 4.16.0, stale instances of RequestListener are reused.

It is common to load images into a single ImageView with Glide. A new RequestListener should be used for each call to Glide, even if it is the same URL.

Up until Glide 4.15.1, newly created listeners are called, but starting in 4.16.0, old listener instances are called.

```kotlin
private fun loadImage(url: String) {
val listener = object : RequestListener {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target,
isFirstResource: Boolean
): Boolean {
Log.d("TAG", "[onLoadFailed] = ${hashCode()}")
return false
}

override fun onResourceReady(
resource: Drawable,
model: Any,
target: Target,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
Log.d("TAG", "[onResourceReady] = ${hashCode()}")
return false
}
}

Log.d("TAG", "[Listener] = ${listener.hashCode()} ==> $url")

Glide.with(binding.imgView)
.load(url)
.centerCrop()
.addListener(listener)
.into(binding.imgView)
}
```

# Demo project

- sample : https://github.com/Pluu/GlideListenerBugSample

## Glide 4.15.1

## Glide 4.16.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.