search

Home  >  Q&A  >  body text

关于Android 内存泄露的问题

如果我在SampleActivity里面定义了一个成员变量ValueAnimator mAnimator,并设置重复方式为无限重复:mAnimator.setRepeatCount(ValueAnimator.INFINITE),将其启动:mAnimator.start();。那么问题来了:当SampleActivity已经销毁后,通过Logcat发现mAnimator还在运行,这样会不会导致Activity内存泄露?

天蓬老师天蓬老师2772 days ago502

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:40:10

    The definition of Activity memory leak is that after the Activity is closed, whether there are other resident objects referencing the Activity object, causing the Activity object not to be recycled.
    From the information you gave, we can’t tell whether it will cause a memory leak, because you didn’t give whether mAnimator references Activity.
    You can directly check the reference chain of mAnimator. If there is a reference to the Activity object (for example, the View operated by ValueAnimator and the callback object of ValueAnimator may cause indirect references to the Activity), it will cause a memory leak.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:40:10

    You can use log to print logs. For example, write a log in the onDestroy method to see if it is called. Print the log in a loop in the activity to see if the log printing will stop after closing.

    reply
    0
  • Cancelreply