From bd34d5cee45a007dd0b3de3d3f31ca5fb5a7ef70 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 5 Mar 2019 18:17:42 +0100 Subject: [PATCH] perf_hooks: clean up GC listeners (#94) 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 45d66ad5917..b3bbc16a3eb 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