From ff3d977f0401eb61e85dfd5a6821f4ab41f0761e 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. PR-URL: https://github.com/nodejs/node/pull/25647 Reviewed-By: Joyee Cheung Reviewed-By: Richard Lau Reviewed-By: James M Snell --- src/node_perf.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node_perf.cc b/src/node_perf.cc index 2b08ecfc1eb61b..d52f26c81b2266 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