From fa17d6ca37b3f434e05e286fb5f828b28bbca93b Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Wed, 7 Apr 2021 15:58:37 +0800 Subject: Clear controls and animations in temp arrays after using them The arrays would be cleared while next time we use them, so they could constantly occupy the memory. This CL clears the temp arrays right after we use them. So they won't occupy the memory while they are not being used. Fix: 183684434 Test: Use Android Memory Profiler to check if there is InsetsAnimationControlImpl or WindowInsetsAnimation instances after GCing after playing insets animation in Launcher. Change-Id: Iaae1e11d1c0cc1a9ac345beb3d7e8b596ea1b4ba --- core/java/android/view/InsetsController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index c001ec9da3a4..b97c63884f48 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -601,8 +601,6 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation return; } - mTmpFinishedControls.clear(); - mTmpRunningAnims.clear(); InsetsState state = new InsetsState(mState, true /* copySources */); for (int i = mRunningAnimations.size() - 1; i >= 0; i--) { RunningAnimation runningAnimation = mRunningAnimations.get(i); @@ -635,10 +633,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation anim.getTypeMask(), anim.getInterpolatedFraction())); } } + mTmpRunningAnims.clear(); for (int i = mTmpFinishedControls.size() - 1; i >= 0; i--) { dispatchAnimationEnd(mTmpFinishedControls.get(i).getAnimation()); } + mTmpFinishedControls.clear(); }; } -- cgit v1.2.3-59-g8ed1b