Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 392832f9 authored by George Mount's avatar George Mount
Browse files

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
parent 87f82bb9
Loading
Loading
Loading
Loading
+3 −16
Original line number Diff line number Diff line
@@ -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) {