Skip to content

Commit fc38b20

Browse files
committed
perf_hooks: clean up GC listeners
Add Environment cleanup hooks to remove GC listeners when the `Environment` is torn down. PR-URL: #25647 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 845bcfa commit fc38b20

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/node_perf.cc

+5
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ inline void SetupGarbageCollectionTracking(Environment* env) {
296296
static_cast<void*>(env));
297297
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
298298
static_cast<void*>(env));
299+
env->AddCleanupHook([](void* data) {
300+
Environment* env = static_cast<Environment*>(data);
301+
env->isolate()->RemoveGCPrologueCallback(MarkGarbageCollectionStart, data);
302+
env->isolate()->RemoveGCEpilogueCallback(MarkGarbageCollectionEnd, data);
303+
}, env);
299304
}
300305

301306
// Gets the name of a function

0 commit comments

Comments
 (0)