diff options
| author | 2023-12-20 15:28:48 -0800 | |
|---|---|---|
| committer | 2023-12-20 15:31:38 -0800 | |
| commit | 392832f9580ff38f1fb0d7de47dbcb17eaaededf (patch) | |
| tree | 6017789d19b431573ceee5d57af065a22172d298 | |
| parent | 87f82bb9ba06450ebba5b65261dc707761dea54a (diff) | |
Remove WeakReference from ObjectAnimator
Fixes: 212993949
ObjectAnimator was using a WeakReference for the target,
but because it is animated every frame, the WeakReference
can never be collected. This CL removes the unnecessary
WeakReference.
Test: ran existing tests
Change-Id: Id688a62d49c8f3f3c86c63dc70b576629f9f137c
| -rw-r--r-- | core/java/android/animation/ObjectAnimator.java | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/core/java/android/animation/ObjectAnimator.java b/core/java/android/animation/ObjectAnimator.java index 1e1f1554d3a2..5840f02a8650 100644 --- a/core/java/android/animation/ObjectAnimator.java +++ b/core/java/android/animation/ObjectAnimator.java @@ -25,8 +25,6 @@ import android.util.Log; import android.util.Property; import android.view.animation.AccelerateDecelerateInterpolator; -import java.lang.ref.WeakReference; - /** * This subclass of {@link ValueAnimator} provides support for animating properties on target objects. * The constructors of this class take parameters to define the target object that will be animated @@ -73,11 +71,7 @@ public final class ObjectAnimator extends ValueAnimator { private static final boolean DBG = false; - /** - * A weak reference to the target object on which the property exists, set - * in the constructor. We'll cancel the animation if this goes away. - */ - private WeakReference<Object> mTarget; + private Object mTarget; private String mPropertyName; @@ -919,7 +913,7 @@ public final class ObjectAnimator extends ValueAnimator { */ @Nullable public Object getTarget() { - return mTarget == null ? null : mTarget.get(); + return mTarget; } @Override @@ -929,7 +923,7 @@ public final class ObjectAnimator extends ValueAnimator { if (isStarted()) { cancel(); } - mTarget = target == null ? null : new WeakReference<Object>(target); + mTarget = target; // New target should cause re-initialization prior to starting mInitialized = false; } @@ -977,13 +971,6 @@ public final class ObjectAnimator extends ValueAnimator { @Override void animateValue(float fraction) { final Object target = getTarget(); - if (mTarget != null && target == null) { - // We lost the target reference, cancel and clean up. Note: we allow null target if the - /// target has never been set. - cancel(); - return; - } - super.animateValue(fraction); int numValues = mValues.length; for (int i = 0; i < numValues; ++i) { |