From 1895d9a4f20e0cf76a965c75de77ad86a1f09320 Mon Sep 17 00:00:00 2001 From: "duanyi.aster" Date: Mon, 30 Oct 2023 22:22:32 +0800 Subject: [PATCH] fix: didn't fully reuse buffer memory --- internal/encoder/stream.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/encoder/stream.go b/internal/encoder/stream.go index b6f3ce5fb..8aa618c5a 100644 --- a/internal/encoder/stream.go +++ b/internal/encoder/stream.go @@ -36,7 +36,8 @@ func NewStreamEncoder(w io.Writer) *StreamEncoder { // Encode encodes interface{} as JSON to io.Writer func (enc *StreamEncoder) Encode(val interface{}) (err error) { - out := newBytes() + buf := newBytes() + out := buf /* encode into the buffer */ err = EncodeInto(&out, val, enc.Opts) @@ -79,6 +80,6 @@ func (enc *StreamEncoder) Encode(val interface{}) (err error) { } free_bytes: - freeBytes(out) + freeBytes(buf) return err }