From e9ab6037350ff6b820c19d250265265b5fdef5e5 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 7c1d5f483..cfe5a3299 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) }) }