From a5d8c157dfb1df282c1c5f5b79dd82a13f498eb7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 22 Jan 2019 23:07:04 +0100 Subject: [PATCH] perf_hooks: clean up GC listeners Add Environment cleanup hooks to remove GC listeners when the `Environment` is torn down. --- src/node_perf.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node_perf.cc b/src/node_perf.cc index 45d66ad5917ab2..b3bbc16a3ebd89 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -296,6 +296,11 @@ inline void SetupGarbageCollectionTracking(Environment* env) { static_cast(env)); env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd, static_cast(env)); + env->AddCleanupHook([](void* data) { + Environment* env = static_cast(data); + env->isolate()->RemoveGCPrologueCallback(MarkGarbageCollectionStart, data); + env->isolate()->RemoveGCEpilogueCallback(MarkGarbageCollectionEnd, data); + }, env); } // Gets the name of a function