Skip to content

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

Open
addaleax wants to merge 4 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 4 commits into
nodejs:mainfrom
addaleax:no-weak-base-object-edges-in-heapdump

Conversation

@addaleax

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

Allowing the addition of child nodes without an explicit 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.

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.

While I still disagree with the decision in 6e60ab7
not to mark strong BaseObjects as proper roots in the
object graph, this commit keeps that decision intact, and only
removes edges to weak BaseObject instances.

Refs: #57417

addaleax added 2 commits June 10, 2026 23:10
Allowing the addition of child nodes without an explicit 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.

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.

While I still disagree with the decision in 6e60ab7
not to mark strong `BaseObject`s as proper roots in the
object graph, this commit keeps that decision intact, and only
removes edges to weak `BaseObject` instances.

Refs: nodejs#57417
Signed-off-by: Anna Henningsen <anna@addaleax.net>
@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
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.

2 participants