import (
"github.com/bytecodealliance/wasmtime-go"
"runtime"
)
func main() {
wasm, err := wasmtime.Wat2Wasm(`
(module
(import "" "hello" (func $hello))
(func (export "run")
(call $hello))
)
`)
check(err)
for {
store := wasmtime.NewStore(wasmtime.NewEngine())
module, err := wasmtime.NewModule(store.Engine, wasm)
check(err)
item := wasmtime.WrapFunc(store, func() {})
instance, err := wasmtime.NewInstance(store, module, []*wasmtime.Extern{item.AsExtern()})
check(err)
// The rest is not required for the leak.
run := instance.GetExport("run").Func()
_, err = run.Call()
check(err)
runtime.GC()
}
}
func check(e error) {
if e != nil {
panic(e)
}
}
Running the following to see the memory leak in action: