bumptech / bumptech/glide

How to know when a Drawable is being released

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

Description

**Glide Version**: 4.12.0

**Issue details / Repro steps / Use case background**:

I am using a custom Drawable which implements the Animatable interface, so Glide will call the start/stop methods, which I need to initiate the drawable animation cycle.
So whenever the ImageView gets cleared, or LifeCycle events get triggered, the drawable stop/start will also trigger as expected.

The issue I am having, is that I cannot find which interface to implement in the drawable that will be called when the ImageView gets cleared.

Next is the onLoadCleared from ImageViewTarget which calls animatable.stop() before clearing it with a placeholder or null.
But the stop at this point doesn't tell the drawable if is being stopped because an onStop lifeCycle event or the onLoadCleared call.

```
public void onLoadCleared(@Nullable Drawable placeholder) {
super.onLoadCleared(placeholder);
if (animatable != null) {
animatable.stop();
}
setResourceInternal(null);
setDrawable(placeholder);
}
```

Is there any interface I can implement to the drawable to let it know is no longer needed? The use case is to know that the Drawable may no longer be used and can release some resources.

I have tried to wrap the Drawable with DrawableResource as I saw it has a recycle method, but it doesn't work because when creating the instance via the custom decoder the DataFetcher.loadData method never gets called if returning a DrawableResource .

If there is no applicable interface or solution, then a future request would be that ImageViewTarget class besides caching Animatable resources, also caches Closeable resources or any other type of interface that could be used to notify the current resource that is no longer needed.

Norte that I cannot extend GifDrawable as the custom drawable is very specific.

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.