Is ValueAnimator safe from memory leak?

Viewed 743

I made an infinite ValueAnimator which holds reference to a view (and view holds reference to Context of course), and the log shows it is not stopped when the view is (supposed to be) destroyed.

    ValueAnimator anim = ValueAnimator.ofFloat(0, 1);
    anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationRepeat(Animator animation) {
                myView.setText(...);
                Log.d("my_tag", "I am still running and repeating");
            }
    });
    anim.setRepeatCount(ValueAnimator.INFINITE);
    anim.start();

Of course I can make it not to hold (strong) reference by extracting the listener as a static inner class and hold a WeakReference instead. However, my question is, in case of finite animator (e.g. anim.setRepeatCount(3)) which stops in a defined time, will it also cause memory leak after the animation is supposed to be ended? (So that I need to do the same weak reference strategy)?

0 Answers
Related