From 5ac357959caccf2a90d43a879e5e80c33daffe62 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 9 Sep 2021 04:27:45 +0900 Subject: [PATCH] internal/graphicscommand: Bug fix: memory leak at q.commands Apparently, the part of a slice between len and cap-1 still holds references. Release them explicitly. Closes #1803 --- internal/graphicscommand/command.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 5c58daa39..cc9814505 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -292,6 +292,13 @@ func (q *commandQueue) flush() error { cs = cs[nc:] } theGraphicsDriver.End() + + // Release the commands explicitly (#1803). + // Apparently, the part of a slice between len and cap-1 still holds references. + // Then, resetting the length by [:0] doesn't release the references. + for i := range q.commands { + q.commands[i] = nil + } q.commands = q.commands[:0] q.nvertices = 0 q.nindices = 0