Skip to content

fix: collect orphaned AnimatedPropsRegistry entry on last animated view unmount#9730

Open
MatiPl01 wants to merge 2 commits into
mainfrom
@matipl01/fix-animatedprops-registry-leak
Open

fix: collect orphaned AnimatedPropsRegistry entry on last animated view unmount#9730
MatiPl01 wants to merge 2 commits into
mainfrom
@matipl01/fix-animatedprops-registry-leak

Conversation

@MatiPl01

Copy link
Copy Markdown
Member

When the last animated view unmounts mid-animation, an in-flight worklet frame can re-add its props to AnimatedPropsRegistry after handleNodeRemovals already drained the tag. The props GC interval has stopped by then (no animated views left) and no further commit drains it, so the entry leaks permanently.

This clears the now fully-orphaned registry one UI frame after the last animated view unmounts (scheduleOnUI -> requestAnimationFrame -> scheduleOnRN), so the late re-add is collected without relying on a further Fabric commit. It also switches the GC view counter to viewsMap.size - the old viewsCount could drift negative for nested AnimatedComponents that share a viewTag, which would skip the cleanup.

Verified on Android (new arch) with the FreezeExample leak meter: the same repro that leaves AnimatedPropsRegistry leaked on main reports it clean with this change.

@MatiPl01 MatiPl01 self-assigned this Jun 21, 2026
…mount

An in-flight worklet frame can re-add an unmounting view's props after handleNodeRemovals drained the tag. With no animated views left the props GC interval has stopped and no further commit drains it, so the entry leaks. Clear the orphaned registry one UI frame after the last view unmounts, and switch the GC view counter to viewsMap.size (the old counter drifted negative for nested AnimatedComponents sharing a viewTag).
@MatiPl01 MatiPl01 force-pushed the @matipl01/fix-animatedprops-registry-leak branch from 2b4d93f to 9b20b33 Compare June 22, 2026 00:06
@MatiPl01 MatiPl01 marked this pull request as ready for review June 22, 2026 03:08
Comment on lines +77 to +81
scheduleOnUI(() => {
'worklet';
requestAnimationFrame(() => {
'worklet';
scheduleOnRN(removeOrphanedProps);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a bit hacky (scheduleOnUI -> requestAnimationFrame -> scheduleOnRN), it might be flaky

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, what exactly are you trying to achieve here? Maybe you can just do setTimeout with some heuristic delay?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants