Skip to content

Commit c59acde

Browse files
Zhang Xiaoweijoeyhuab
authored andcommitted
Avoid memory leak of activity in ExitTransitionCoordinator
During the use of makeSceneTransitionAnimation(), two ExitTransitionCoordinator instances are generated, corresponding to the activity before the transition and the activity after the transition, respectively. The activity after the transition is released after finishing() when finishAfterTransition() is called. However, the activity before the transition is leaked in ExitTransitionCoordinator because mExitCallbacks holds it and cannot be released.. We found that the reason why the activity before the transition cannot reach finish() is that mIsReturning is always false.Therefore, we modified finishIfNecessary() to release the activity to avoid the leak. Change-Id: I795f4c85ebb85a5fb8448738e127f7b07cf8ef35
1 parent 216a28c commit c59acde

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

core/java/android/app/ExitTransitionCoordinator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,13 @@ private void notifyExitComplete() {
466466
}
467467

468468
private void finishIfNecessary() {
469-
if (mIsReturning && mExitNotified && mExitCallbacks != null && (mSharedElements.isEmpty()
470-
|| mSharedElementsHidden)) {
471-
finish();
469+
if (!mExitNotified || mExitCallbacks == null || (!mSharedElements.isEmpty() && !mSharedElementsHidden)) {
470+
return;
471+
}
472+
if (mIsReturning) {
473+
finish();
474+
} else {
475+
mExitCallbacks = null;
472476
}
473477
}
474478

0 commit comments

Comments
 (0)