Skip to content

fix(core): release replaced nodes in the validation binding tracker - #965

Closed
shahabdsh wants to merge 1 commit into
player-ui:mainfrom
shahabdsh:fix/binding-tracker-resolved-node-map
Closed

shahabdsh wants to merge 1 commit into
player-ui:mainfrom
shahabdsh:fix/binding-tracker-resolved-node-map

Conversation

@shahabdsh

Copy link
Copy Markdown
Contributor

ValidationBindingTrackerViewPlugin keeps every node that any update of a view resolves, for as long as the view stays current. A view whose data changes often grows memory with each update, and gets it back only when Player moves to another view.

Why it's needed

The tracker maps each resolved node to its source node in resolvedNodeMap, so it can carry validation bindings from one update to the next. When the root node finishes an update, it clears its other per-update maps, but not resolvedNodeMap. Each entry holds a resolved node and, through its children, that node's whole resolved subtree. So every update adds the nodes it resolved again, and the ones they replaced are never released.

Any view that updates repeatedly while it stays on screen is affected: typing into inputs, polling, or data a plugin loads in the background. In a measurement with a view of 200 text assets updated 200 times, the heap grew by 14.24 MB on main and by 0.30 MB with this change.

Change

Clear resolvedNodeMap with the other maps when the root finishes an update. The map is read only at that moment, and every node resolved in an update sets its entry before the root finishes, so nothing reads an entry this clears.

Tests

binding-tracker.test.ts updates a view 20 times, holds the nodes each update resolved in WeakRefs, forces garbage collection, and checks that the nodes later updates replaced were released. On main, 19 replaced nodes are still held after garbage collection; with the change, none are. The test turns on gc with v8.setFlagsFromString("--expose-gc"), because vitest doesn't pass Node flags through to tests.

Change Type (required)

Indicate the type of change your pull request is:

  • patch
  • minor
  • major
  • N/A

Does your PR have any documentation updates?

  • Updated docs
  • No Update needed
  • Unable to update docs

ValidationBindingTrackerViewPlugin maps each resolved node to its source
node so it can carry binding trees from one update to the next. It
cleared every other per-update map at the end of each root update, but
never resolvedNodeMap, so the map kept every node any update had
resolved, with its resolved subtree, for as long as the view was
current.

Clear the map with the others. It's only read while the root finishes
an update, and every node in that update sets its entry first.
@shahabdsh
shahabdsh requested a review from a team as a code owner November 10, 2026 18:28
@shahabdsh

Copy link
Copy Markdown
Contributor Author

Replaced by #966, opened from a branch in this repository so the three PRs can be stacked.

@shahabdsh shahabdsh closed this Nov 10, 2026
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