From 334c7becc06a47ab968b3b61622bb5e957b1bc24 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Sat, 14 Dec 2024 15:15:40 -0300 Subject: [PATCH] fn/ContextGuard: clear store of cancel funcs If ContextGuard lives for some time after Quit method is called, the map won't be collected by GC. Optimization. --- fn/context_guard.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fn/context_guard.go b/fn/context_guard.go index 7c1d5f4832b..cfe5a32998c 100644 --- a/fn/context_guard.go +++ b/fn/context_guard.go @@ -51,6 +51,10 @@ func (g *ContextGuard) Quit() { cancel() } + // Clear cancelFns. It is safe to use nil, because no write + // operations to it can happen after g.quit is closed. + g.cancelFns = nil + close(g.quit) }) }