Files
node/test/pummel/test-heapdump-vm-script.js
T
Shelley Vohr 3a15c5d1a5 src: free placeholder nodes for cppgc wrappers in MemoryTracker
`MemoryTracker::AddNode(const CppgcMixin*)` allocates a
`MemoryRetainerNode` that only stands in for the wrapper's JS node while
its `MemoryInfo()` runs; unlike the other node kinds it is not handed
to the `EmbedderGraph`, and nothing freed it. Every heap snapshot (or
other `BuildEmbedderGraph` call) leaked one node per live `vm.Script`
or `vm` context.

Keep the placeholders in the tracker and free them with it, and make
the already-seen path in `Track(const CppgcMixin*)` add its edge to the
wrapper's JS node like the first visit does, so the graph never refers
to a placeholder.

Refs: https://github.com/nodejs/node/pull/56534
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65793
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-09-22 12:00:22 +00:00

16 lines
559 B
JavaScript

'use strict';
require('../common');
const { validateByRetainingPath } = require('../common/heap');
const vm = require('vm');
const source = 'const foo = 123';
const script = new vm.Script(source);
const context = vm.createContext();
validateByRetainingPath('Node / ContextifyScript', [
{ node_name: '(shared function info)' }, // This is the UnboundScript referenced by ContextifyScript.
{ edge_name: 'script' },
{ edge_name: 'source', node_type: 'string', node_name: source },
]);
console.log(script, context); // Keep the script and context alive.