aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/java/com
diff options
context:
space:
mode:
authorSam Judd <judds@google.com>2014-10-21 08:19:48 -0700
committerSam Judd <judds@google.com>2014-10-21 08:29:41 -0700
commit6958330c93825bbfb70aea1aff9aeed76b59af4e (patch)
tree49cc0b1530b1c810bdcaff98e5702ede8aa56e7b /library/src/main/java/com
parentb4cc7fa5f667e4a56514823cf2ad85d7435b498a (diff)
downloadglide-6958330c93825bbfb70aea1aff9aeed76b59af4e.tar.gz
Clean up GifDrawable resources more reliably.
Each time we call get() on a drawable resource, we get a new Drawable. We call get() repeatedly on resources when they are retrieved from either the set of active resources or the in memory cache. Each time we create a new GifDrawable it holds on to one or two temporary Bitmaps outside it's shared state to render the current frame and obey the dispose_previous method. This change means we more aggressively cleanup those resources when we think each Drawable is no longer being used. The side affect is that we may reset back to the beginning of the Drawable in some circumstances. Cleanup in in memory resources makes it less likely that frames would be retrieved from in memory, so this also works toward #207.
Diffstat (limited to 'library/src/main/java/com')
-rw-r--r--library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java19
-rw-r--r--library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java4
2 files changed, 22 insertions, 1 deletions
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
index acf1058d..fd5ea782 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
@@ -133,6 +133,22 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
public void stop() {
isStarted = false;
stopRunning();
+
+ // On APIs > honeycomb we know our drawable is not being displayed anymore when it's callback is cleared and so
+ // we can use the absence of a callback as an indication that it's ok to clear our temporary data. Prior to
+ // honeycomb we can't tell if our callback is null and instead eagerly reset to avoid holding on to resources we
+ // no longer need.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
+ reset();
+ }
+ }
+
+ /**
+ * Clears temporary data and resets the drawable back to the first frame.
+ */
+ private void reset() {
+ frameManager.clear();
+ invalidateSelf();
}
private void startRunning() {
@@ -222,8 +238,9 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onFrameRead(int frameIndex) {
- if (Build.VERSION_CODES.HONEYCOMB <= Build.VERSION.SDK_INT && getCallback() == null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && getCallback() == null) {
stop();
+ reset();
return;
}
if (!isRunning) {
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java
index 42eea5d0..661e84d9 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java
@@ -100,11 +100,15 @@ class GifFrameManager {
if (current != null) {
mainHandler.removeCallbacks(current);
Glide.clear(current);
+ current = null;
}
if (next != null) {
mainHandler.removeCallbacks(next);
Glide.clear(next);
+ next = null;
}
+
+ decoder.resetFrameIndex();
}
class DelayTarget extends SimpleTarget<Bitmap> implements Runnable {