fix: Memory leak when unmounting views mid-animation#9711
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Android memory leak in Fabric mounting where tearing down a view subtree mid-animation could leave removed nodes (and their scheduled CSS animations) registered indefinitely. The mount hook no longer returns early on Reanimated-originated mounts, ensuring removal draining always runs while still only unpausing commits on React-originated mounts.
Changes:
- Compute whether the mount was initiated by Reanimated via
ReanimatedMountTrait, and always unset the trait for cleanliness. - Always call
UpdatesRegistryManager::handleNodeRemovals(even on Reanimated mounts) to prevent leaks during per-frame animation mounts. - Gate
unpauseReanimatedCommits()/requestFlush_()so they only run after React commits.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tomekzaw
approved these changes
Jun 22, 2026
ReanimatedMountHook skipped handleNodeRemovals on Reanimated's own commits. While CSS animations run, every mount carries the mount trait, so the cleanup never ran for the duration of the animation. Tearing the view tree down mid-animation then leaked the unmounted nodes (and their still-scheduled CSS animations) in all update registries on Android. Always run handleNodeRemovals; gate only the commit-unpause on React commits.
157cdd7 to
14b2e6b
Compare
This was referenced Jun 24, 2026
MatiPl01
added a commit
that referenced
this pull request
Jul 2, 2026
…ion (#9711) (#9830) ## Summary Cherry-picking for Reanimated 4.3.2 release - #9711 ## Cherry-pick notes Conflict resolution: on 4.3-stable the early return lived directly in the mount-trait block (and 4.3 has no `setLastMountedRoot`, which came with #9715), so the change was applied on 4.3's shape - `handleNodeRemovals` now always runs and only the unpause is gated on the commit not being a Reanimated mount. Same semantics as on main.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an Android memory leak: tearing down a view subtree while CSS animations are running left the unmounted nodes (and their still-scheduled animations) in every update registry.
ReanimatedMountHookreturned early on Reanimated's own commits and skippedhandleNodeRemovals, so while an animation runs (every frame is a Reanimated commit) the cleanup never ran. It now always drains removable nodes on mount and only gates the commit-unpause on React commits.