diff --git a/encode.go b/encode.go index 1fff880..eb2f1e3 100644 --- a/encode.go +++ b/encode.go @@ -164,6 +164,7 @@ func (e *Encoder) encode(v interface{}) error { } ctx := codeSet.ctx.Get().(*encodeRuntimeContext) p := uintptr(header.ptr) + ctx.reset() ctx.init(p) err := e.run(ctx, code) if e.enabledIndent { @@ -218,6 +219,7 @@ func (e *Encoder) encode(v interface{}) error { cachedOpcode.set(typeptr, codeSet) p := uintptr(header.ptr) ctx := codeSet.ctx.Get().(*encodeRuntimeContext) + ctx.reset() ctx.init(p) if e.enabledIndent { err := e.run(ctx, codeIndent) diff --git a/encode_context.go b/encode_context.go index da3d233..0c7ee1b 100644 --- a/encode_context.go +++ b/encode_context.go @@ -63,6 +63,10 @@ type encodeRuntimeContext struct { seenPtr map[uintptr]struct{} } +func (c *encodeRuntimeContext) reset() { + c.seenPtr = map[uintptr]struct{}{} +} + func (c *encodeRuntimeContext) init(p uintptr) { c.ptrs[0] = p }