Skip to content

fix(android): don't reuse a CustomTransition's animator between runs - #13

Merged
farfromrefug merged 1 commit into
mainfrom
fix/android-custom-transition-animator-leak
Nov 5, 2026
Merged

farfromrefug merged 1 commit into
mainfrom
fix/android-custom-transition-animator-leak

Conversation

@farfromrefug

Copy link
Copy Markdown

What is the current behavior?

CustomTransition.setAnimatorsTarget adds its listeners to the AnimatorSet given to the constructor and returns that same instance on every run. Nothing removes them, so each navigation leaves, on an animator the transition keeps alive:

  • a CustomAnimatorListener holding the animated view,
  • the Transition$2 and Visibility$DisappearListener androidx adds (they reach the transition clone and its mEndValues, i.e. the views).

Every page that ever animated stays alive: PageLayout, its collectionviews, map views, with the native memory they hold. Heap dump after 11 open/close cycles: 48 CustomAnimatorListener pinning 15 distinct PageLayouts, one AnimatorSet with 10 of each listener.

What is the new behavior?

setAnimatorsTarget clones the AnimatorSet for each run, so the listeners go away with the clone.

Measured on an app (emulator, forced GC after each cycle, QuickJS-ng runtime, 4 to 5 cycles each; V8 showed the same page retention before the fix):

cycle Views retained per cycle, before to after
open/close a pushed page +47 to +4
open a page, then a page on top, back twice about +130 to +10
Settings page +89 to +30

PageLayout instances left in a heap dump: 15 to 0; hero TextureMapViews: 4 to 0.

Verification

  • ./gradlew assembleRelease on ui-mobile-base/android builds.
  • Run in an app through a portal: to this package, numbers above. No unit test: there is no Java test setup for the widgets.
  • Not checked: transition visuals across all CustomTransition users (custom, flip, shared element). The animator is now one clone per onAppear/onDisappear call; resetOnTransitionEnd clones that same per-run instance. A quick visual pass on those is worth doing.

Notes

  • Some retention remains on QuickJS-ng alpha only (collectionview cell holders kept by the runtime); not part of this PR.
  • The CLA / issue / tests boxes of the template are for upstream and left out.

🤖 Generated with Claude Code

setAnimatorsTarget added its listeners to the AnimatorSet given to the constructor and
returned that same instance on every run. Nothing removes them, so each navigation left a
CustomAnimatorListener holding the animated view, plus the Transition$2 and DisappearListener
that androidx adds, on an animator the transition keeps alive. Every page that ever animated
was kept alive with it (PageLayout, collectionviews, map views).

Clone the AnimatorSet for each run so the listeners go away with it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@farfromrefug
farfromrefug marked this pull request as ready for review November 5, 2026 10:23
@farfromrefug
farfromrefug merged commit 83c7f05 into main Nov 5, 2026
1 of 3 checks passed
@farfromrefug
farfromrefug deleted the fix/android-custom-transition-animator-leak branch November 6, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant