src: do not track weak BaseObjects as childrens of Realms#63842
Open
addaleax wants to merge 3 commits into
Open
src: do not track weak BaseObjects as childrens of Realms#63842addaleax wants to merge 3 commits into
BaseObjects as childrens of Realms#63842addaleax wants to merge 3 commits into
Conversation
Allowing the addition of child nodes with a weak edge between them enables expressing a relationship of the "node A keeps track of node B and no other node does, but node A does not keep node B alive" kind, which is the relationship between `Realm`s and weak `BaseObject` instances. This is a prerequisite for the following commit. Note that the relevant V8 feature is not available in Node.js yet. It's still worth doing this, both because it allows us to prepare for that upstream change, and because the current representation of these edges in heap dumps is factually incorrect and hinders debugging in existing Node.js versions. Refs: v8/v8@e37cadf Signed-off-by: Anna Henningsen <anna@addaleax.net>
Heap dumps are used for analyzing the relationship between objects that keep each other alive, so that retainers of memory can be detected and memory leaks fixed. 6e60ab7 broke this for a wide range of `BaseObject` instances. Marking all `BaseObject`s, including weak ones, as children of `Realm` and `Environment` instances gives the incorrect impression that they are held alive by those objects, effectively hiding the "real" set of strong roots that keep other objects alive through GC. An upcoming change in V8 will allow us to represent this relationship between `Realm` and `Environment` and its `BaseObject` and `CppgcMixin` instances properly. Refs: v8/v8@e37cadf Refs: nodejs#57417 Signed-off-by: Anna Henningsen <anna@addaleax.net>
f0f2ac2 to
d7df262
Compare
legendecas
reviewed
Jun 12, 2026
Collaborator
legendecas
approved these changes
Jun 12, 2026
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.
src: allow tracking children in
MemoryTrackerwith weak edgesAllowing the addition of child nodes with a weak edge
between them enables expressing a relationship of the
"node A keeps track of node B and no other node does,
but node A does not keep node B alive" kind, which is
the relationship between
Realms and weakBaseObjectinstances.This is a prerequisite for the following commit.
Note that the relevant V8 feature is not available
in Node.js yet. It's still worth doing this, both
because it allows us to prepare for that upstream
change, and because the current representation of
these edges in heap dumps is factually incorrect
and hinders debugging in existing Node.js versions.
Refs: v8/v8@e37cadf
src: do not track weak
BaseObjects as childrens ofRealmsHeap dumps are used for analyzing the relationship between
objects that keep each other alive, so that retainers of
memory can be detected and memory leaks fixed.
6e60ab7 broke this for a wide range of
BaseObjectinstances. Marking all
BaseObjects, including weak ones,as children of
RealmandEnvironmentinstances givesthe incorrect impression that they are held alive by those
objects, effectively hiding the "real" set of strong roots
that keep other objects alive through GC.
An upcoming change in V8 will allow us to represent this
relationship between
RealmandEnvironmentand itsBaseObjectandCppgcMixininstances properly.Refs: v8/v8@e37cadf
Refs: #57417