Skip to content

src: do not track weak BaseObjects as childrens of Realms#63842

Open
addaleax wants to merge 3 commits into
nodejs:mainfrom
addaleax:no-weak-base-object-edges-in-heapdump
Open

src: do not track weak BaseObjects as childrens of Realms#63842
addaleax wants to merge 3 commits into
nodejs:mainfrom
addaleax:no-weak-base-object-edges-in-heapdump

Conversation

@addaleax

@addaleax addaleax commented Jun 10, 2026

Copy link
Copy Markdown
Member
src: allow tracking children in MemoryTracker with weak edges

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 Realms 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

src: do not track weak BaseObjects as childrens of Realms

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 BaseObjects, 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: #57417

@addaleax addaleax requested a review from joyeecheung June 10, 2026 21:39
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 10, 2026

@joyeecheung joyeecheung left a comment

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.

LGTM % nits

Comment thread src/base_object.cc Outdated
addaleax added 2 commits June 12, 2026 15:14
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>
@addaleax addaleax force-pushed the no-weak-base-object-edges-in-heapdump branch from f0f2ac2 to d7df262 Compare June 12, 2026 13:17
@addaleax addaleax requested a review from joyeecheung June 12, 2026 13:18

@joyeecheung joyeecheung left a comment

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.

LGTM, thanks

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 12, 2026
Comment thread src/base_object.cc Outdated
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 12, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants