diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index db2ebbc..b0ab8dd 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -19,7 +19,12 @@ jobs: uses: actions/checkout@v2 - name: Test - run: go test -v ./ + run: go test -v ./ -count=1 - - name: Test with race detector - run: go test -v -race ./ + - name: Test with GC + run: go test -v ./ -count=1 + env: + GOGC: 1 + + # - name: Test with race detector + # run: go test -v -race ./ -count=1 diff --git a/encode_vm.go b/encode_vm.go index 744e592..2a83ca0 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -216,6 +216,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { } seenPtr[ptr] = struct{}{} v := e.ptrToInterface(code, ptr) + ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v)) rv := reflect.ValueOf(v) if rv.IsNil() { e.encodeNull() @@ -292,6 +293,7 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, code *opcode) error { } seenPtr[ptr] = struct{}{} v := e.ptrToInterface(code, ptr) + ctx.keepRefs = append(ctx.keepRefs, unsafe.Pointer(&v)) rv := reflect.ValueOf(v) if rv.IsNil() { e.encodeNull() diff --git a/json_test.go b/json_test.go index f3a066c..1ed0074 100644 --- a/json_test.go +++ b/json_test.go @@ -225,9 +225,6 @@ var ( ) func initBig() { - if len(jsonBig) > 0 { - return - } n := 10000 if testing.Short() { n = 100