From 6bf188fb2f8424fed9e3b465e2432488afe160ba Mon Sep 17 00:00:00 2001 From: Mukti Date: Wed, 9 Oct 2024 18:32:17 +0700 Subject: [PATCH] pref: clear filedef's listener fields' pool on Close (#490) --- profile/filedef/listener.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/profile/filedef/listener.go b/profile/filedef/listener.go index bb0f8161..caecdd72 100644 --- a/profile/filedef/listener.go +++ b/profile/filedef/listener.go @@ -182,6 +182,15 @@ func (l *Listener) Close() { return } close(l.mesgc) + + // PERF: In case the Listener might be reused later, this ensure fields' pool does not reference any pointer + // such as proto.FieldBase created for unknown fields or field.Value that reference any pointer to a slice. + for i := uint(0); i < l.options.channelBuffer; i++ { + fields := <-l.poolc + clear(fields[:cap(fields):cap(fields)]) + l.poolc <- fields + } + <-l.done l.active = false }