如果我在SampleActivity
里面定義了一個成員變量ValueAnimator mAnimator
,并設置重復方式為無限重復:mAnimator.setRepeatCount(ValueAnimator.INFINITE)
,將其啟動:mAnimator.start();
。那么問題來了:當SampleActivity
已經銷毀后,通過Logcat發(fā)現mAnimator還在運行,這樣會不會導致Activity內存泄露?
歡迎選擇我的課程,讓我們一起見證您的進步~~
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.
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.