From c05b63d8b2a045bf544fdd5b6f73d6763837af5b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 21 Jul 2020 23:27:38 +0200 Subject: [PATCH] src: skip weak references for memory tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The memory tracking is supposed to represent the “keeps-alive” relations between objects for a heap dump, in order to enable developers to figure out which objects keep which other objects on the heap. Weak references do not participate in that relation. Therefore, we should not be tracking them. PR-URL: https://github.com/nodejs/node/pull/34469 Reviewed-By: Richard Lau Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Michael Dawson --- src/memory_tracker-inl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/memory_tracker-inl.h b/src/memory_tracker-inl.h index 9e6201442ab6b1..4167064847253e 100644 --- a/src/memory_tracker-inl.h +++ b/src/memory_tracker-inl.h @@ -131,7 +131,7 @@ template void MemoryTracker::TrackField(const char* edge_name, const BaseObjectPtrImpl& value, const char* node_name) { - if (value.get() == nullptr) return; + if (value.get() == nullptr || kIsWeak) return; TrackField(edge_name, value.get(), node_name); } @@ -214,6 +214,7 @@ template void MemoryTracker::TrackField(const char* edge_name, const v8::PersistentBase& value, const char* node_name) { + if (value.IsWeak()) return; TrackField(edge_name, value.Get(isolate_)); }