bumptech / bumptech/glide

Is this a bug in ImageViewTarget?

Open
#4,598 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

I recently debug an app that loads image with Glide. The app implments a method to load image by folowing code:
![image](https://user-images.githubusercontent.com/13826031/126580107-3d047fcd-ca31-4cbc-b878-3719dabdcd13.png)

The `ResourceBuilder.into( ImageView view )` method provided by Glide further invokes `ResourceBuilder.into( v target, RequestListener targetListener,RequestOptions options)` with a new created `ImageViewTarget `via :
![image](https://user-images.githubusercontent.com/13826031/126580228-b1c25e36-f11e-45c1-bef6-bfa929a5da01.png)

In the invoked method, Glide would first tries to clear the `target`
![image](https://user-images.githubusercontent.com/13826031/126580580-a69f3dde-450b-40b5-b8e1-5a928679849d.png)

the `clear()` method would finally call the `TargetTracker.untrack(Target target)` method to remove the target.
![image](https://user-images.githubusercontent.com/13826031/126580708-14233fd0-a6f1-4261-b247-308d9932bae1.png)

However, the target is obtained by `GlideContext.buildImageViewTarget()`, which create a new Target object when be called.
So, the new `target ` instance cannot be found in the `targets`, even if there is one Target in `targets` points to the same View.

And after running the app for a period of time, the `targets` would contains a lot of instances of ImageViewTarget, many of which point to the same View object.

I think this might be a problem, and `ImageViewTarget` should override the `hashCode()` and `equals()` methods based on the View object it contains, so as to be uniquely identified.

For example, I got 50 instances in `targets` with Glide:
![image](https://user-images.githubusercontent.com/13826031/126581706-370bdbd6-51f3-42f3-be8b-298b454e73c9.png)

After I overrided the `hashCode()` and `equals()` methods, I got only 13 instances in `targets`:
![image](https://user-images.githubusercontent.com/13826031/126581852-a00fc3cd-75d5-4852-9b3f-b6c5293f8d6d.png)

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.