Skip to content

Commit 30f03ac

Browse files
committed
DO NOT MERGE. Fix leak in LayoutTransition
LayoutTransition was making an incorrect assumption that there could only be one transition animation on a child of a transitioning container. But if multiple children are added/removed to/from that container, there would be multiple calls to set up changing animations for each existing child of that container. This meant that the child would have multiple, new OnLayoutChangeListeners added to it as part of the setup process. Meanwhile, we would cache only the latest listener in a hashmap that used the child as a key for the listener. Then when we cleaned up the hashmap later, we would remove only the latest listener from the child, leaving the rest there for eternity. The fix is to skip the setup entirely for children that already have listeners set on them; they must, if that's the case, already have been set up and are already listening for layout changes. Setting up the animation is redundant, and adding another listener is a leak. issue #5588509: memory leak in systemui Change-Id: Ie2192593d84702be7243c18760dfdb3a027b761c
1 parent ca5c881 commit 30f03ac

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/java/android/animation/LayoutTransition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@ public void setAnimateParentHierarchy(boolean animateParentHierarchy) {
657657
*/
658658
private void setupChangeAnimation(final ViewGroup parent, final int changeReason,
659659
Animator baseAnimator, final long duration, final View child) {
660+
661+
// If we already have a listener for this child, then we've already set up the
662+
// changing animation we need. Multiple calls for a child may occur when several
663+
// add/remove operations are run at once on a container; each one will trigger
664+
// changes for the existing children in the container.
665+
if (layoutChangeListenerMap.get(child) != null) {
666+
return;
667+
}
668+
660669
// Make a copy of the appropriate animation
661670
final Animator anim = baseAnimator.clone();
662671

0 commit comments

Comments
 (0)