src: free placeholder nodes for cppgc wrappers in MemoryTracker · nodejs/node@68931f7 · GitHub
Skip to content

Commit 68931f7

Browse files
codebytereaduh95
authored andcommitted
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: #56534 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com> PR-URL: #65793 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ee457cd commit 68931f7

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎src/memory_tracker-inl.h‎

Lines changed: 8 additions & 2 deletions

‎src/memory_tracker.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#include <uv.h>
99

1010
#include <limits>
11+
#include <memory>
1112
#include <queue>
1213
#include <stack>
1314
#include <string>
1415
#include <unordered_map>
16+
#include <vector>
1517

1618
namespace v8 {
1719
class BackingStore;
@@ -294,9 +296,8 @@ class MemoryTracker {
294296
inline v8::EmbedderGraph* graph() { return graph_; }
295297
inline v8::Isolate* isolate() { return isolate_; }
296298

297-
inline explicit MemoryTracker(v8::Isolate* isolate,
298-
v8::EmbedderGraph* graph)
299-
: isolate_(isolate), graph_(graph) {}
299+
inline explicit MemoryTracker(v8::Isolate* isolate, v8::EmbedderGraph* graph);
300+
inline ~MemoryTracker();
300301

301302
// Can be passed to Track() if it is not desirable
302303
// to create a strong edge between nodes, i.e. when
@@ -334,6 +335,8 @@ class MemoryTracker {
334335
v8::EmbedderGraph* graph_;
335336
std::stack<MemoryRetainerNode*> node_stack_;
336337
NodeMap seen_;
338+
// Placeholder nodes for cppgc wrappers; the graph only owns their JS nodes.
339+
std::vector<std::unique_ptr<MemoryRetainerNode>> cppgc_nodes_;
337340
};
338341

339342
} // namespace node
Lines changed: 4 additions & 2 deletions

0 commit comments

Comments
 (0)