Skip to content

WeakMap memory leak #199

@lujjjh

Description

@lujjjh
package gojatest

import (
	"runtime"
	"testing"
	"time"

	"github.com/dop251/goja"
)

func TestWeakMap(t *testing.T) {
	for i := 0; i < 100; i++ {
		r := goja.New()
		r.RunScript("", "var x = {}; new WeakMap().set(x, {})")
		r = nil
	}
	runtime.GC()
	time.Sleep(100 * time.Millisecond)
	runtime.GC()
	time.Sleep(100 * time.Millisecond)
}
$ go test weakmap_test.go -memprofile=/tmp/heap

There are still tons of inuse_objects:

Still have no idea why (it seems to be related with runtime.SetFinalizer).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions