Skip to content

fix: don't leak GC roots in Table::copy - #14627

Merged
rvolosatovs merged 1 commit into
bytecodealliance:mainfrom
rvolosatovs:fix/copy-gc-roots
Oct 9, 2026
Merged

rvolosatovs merged 1 commit into
bytecodealliance:mainfrom
rvolosatovs:fix/copy-gc-roots

Conversation

@rvolosatovs

Copy link
Copy Markdown
Member

Table::copy copies each element by reading it with Table::get and writing it with Table::set. For GC reference tables, Table::get creates a LIFO Rooted in the caller's current root scope. Nothing in Table::copy released those roots, so when it was called on a plain &mut Store rather than inside a RootScope, every copied object stayed rooted until the store was dropped. Repeated copies grew the root set and kept the GC heap from shrinking across collections.

Enter a GC LIFO scope around each element's get/set pair and exit it afterwards, so the temporary root is released before the next element is copied.

`Table::copy` copies each element by reading it with `Table::get` and
writing it with `Table::set`. For GC reference tables, `Table::get`
creates a LIFO `Rooted` in the caller's current root scope. Nothing in
`Table::copy` released those roots, so when it was called on a plain
`&mut Store` rather than inside a `RootScope`, every copied object stayed
rooted until the store was dropped. Repeated copies grew the root set and
kept the GC heap from shrinking across collections.

Enter a GC LIFO scope around each element's get/set pair and exit it
afterwards, so the temporary root is released before the next element
is copied.

Assisted-by: claude:claude-opus-5-5
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs
rvolosatovs requested a review from a team as a code owner October 9, 2026 16:34
@rvolosatovs
rvolosatovs requested review from pchickey and removed request for a team October 9, 2026 16:34
@rvolosatovs
rvolosatovs enabled auto-merge October 9, 2026 16:36
@rvolosatovs
rvolosatovs added this pull request to the merge queue Oct 9, 2026
Merged via the queue into bytecodealliance:main with commit 9150a9a Oct 9, 2026
53 checks passed
@rvolosatovs
rvolosatovs deleted the fix/copy-gc-roots branch October 9, 2026 17:32
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.

2 participants