From 9f465009b10af78069f3ef81e0a54601ade655eb 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 97be794bb86ba5..36ef0f5b38403c 100644 --- a/src/memory_tracker-inl.h +++ b/src/memory_tracker-inl.h @@ -121,7 +121,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); } @@ -204,6 +204,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_)); }