Remove bitmap recycling (#1013)
Fixes #1002
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index 3695345..648503b 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -163,25 +163,16 @@
}
@Override public void setImageResource(int resId) {
- recycleBitmaps();
cancelLoaderTask();
super.setImageResource(resId);
}
@Override public void setImageDrawable(Drawable drawable) {
- setImageDrawable(drawable, true);
- }
-
- private void setImageDrawable(Drawable drawable, boolean recycle) {
- if (recycle && drawable != lottieDrawable) {
- recycleBitmaps();
- }
cancelLoaderTask();
super.setImageDrawable(drawable);
}
@Override public void setImageBitmap(Bitmap bm) {
- recycleBitmaps();
cancelLoaderTask();
super.setImageBitmap(bm);
}
@@ -247,16 +238,9 @@
cancelAnimation();
wasAnimatingWhenDetached = true;
}
- recycleBitmaps();
super.onDetachedFromWindow();
}
- @VisibleForTesting void recycleBitmaps() {
- // AppCompatImageView constructor will set the image when set from xml
- // before LottieDrawable has been initialized
- lottieDrawable.recycleBitmaps();
- }
-
/**
* Enable this to get merge path support for devices running KitKat (19) and above.
*
@@ -744,8 +728,8 @@
public void setScale(float scale) {
lottieDrawable.setScale(scale);
if (getDrawable() == lottieDrawable) {
- setImageDrawable(null, false);
- setImageDrawable(lottieDrawable, false);
+ setImageDrawable(null);
+ setImageDrawable(lottieDrawable);
}
}
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
index a10d594..8d9208a 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
@@ -178,19 +178,6 @@
}
/**
- * If you have image assets and use {@link LottieDrawable} directly, you must call this yourself.
- *
- * Calling recycleBitmaps() doesn't have to be final and {@link LottieDrawable}
- * will recreate the bitmaps if needed but they will leak if you don't recycle them.
- *
- */
- public void recycleBitmaps() {
- if (imageAssetManager != null) {
- imageAssetManager.recycleBitmaps();
- }
- }
-
- /**
* Create a composition with {@link LottieCompositionFactory}
*
* @return True if the composition is different from the previously set composition, false otherwise.
@@ -244,7 +231,6 @@
}
public void clearComposition() {
- recycleBitmaps();
if (animator.isRunning()) {
animator.cancel();
}
@@ -848,7 +834,6 @@
}
if (imageAssetManager != null && !imageAssetManager.hasSameContext(getContext())) {
- imageAssetManager.recycleBitmaps();
imageAssetManager = null;
}
diff --git a/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java b/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
index 27afc5a..da4568d 100644
--- a/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
+++ b/lottie/src/main/java/com/airbnb/lottie/manager/ImageAssetManager.java
@@ -117,20 +117,6 @@
return putBitmap(id, bitmap);
}
- public void recycleBitmaps() {
- synchronized (bitmapHashLock) {
- for (Map.Entry<String, LottieImageAsset> entry : imageAssets.entrySet()) {
- LottieImageAsset asset = entry.getValue();
- Bitmap bitmap = asset.getBitmap();
- if (bitmap != null) {
- bitmap.recycle();
- asset.setBitmap(null);
- }
- }
- }
- }
-
-
public boolean hasSameContext(Context context) {
return context == null && this.context == null || this.context.equals(context);
}