-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak with go-wasm-adapter/go-wasm #282
Comments
Hello, So, you're compiling a Go program to Wasm, to execute it in Go. OK. First, why doing that :-)? I'm curious. |
Hello, First, I want to make a tool to run go programs by wasm.
I update "syscall/js.finalizeRef" and optimized it. func finalizeRef(env interface{}, v []wasmer.Value) (out []wasmer.Value, err error) {
sp := v[0].I32()
b := getRuntime(env)
// log.Println("finalizeRef: ", len(b.valueMap), ", refs: ", len(b.refs), ", refcout: ", len(b.refCount))
id := int(b.getUint32(sp + 8))
b.valuesMu.RLock()
b.refCount[id]--
if b.refCount[id] == 0 {
v, ok := b.valueMap[id]
if ok {
rt := reflect.TypeOf(v)
if rt.Kind() == reflect.Ptr {
rt = rt.Elem()
}
rv := v
if !rt.Comparable() {
rv = reflect.ValueOf(v)
}
delete(b.refs, rv)
delete(b.valueMap, id)
delete(b.refCount, id)
// b.idPools = append(b.idPools, id)
}
}
b.valuesMu.RUnlock()
return
} The end of demo, I run Release(), set them "nil" func (b *Runtime) ClearInstance() {
b.instance = nil
b.valueMap = nil
b.refs = nil
b.valueIDX = 8
b.refCount = nil
b.memory = nil
}
func (b *Runtime) mem(offset int32) []byte {
m, _ := b.instance.Exports.GetMemory("mem")
if b.memory == nil {
b.memory = m.Data()
}
if len(b.memory) <= int(offset) {
m.Grow(1)
b.memory = m.Data()
}
return b.memory
}
I can't judge the real cause. So, can you help me find the reason?
|
I'm sorry but you should open a PR on I'm closing the issue. Please reopen it at https://github.com/go-wasm-adapter/go-wasm/. Thank you. |
Thanks for the bug report!
Describe the bug
I referenced "github.com/go-wasm-adapter/go-wasm" and updated it to support wasmer-go 1.0+.
When I create an instance with bridge(go-wasm) and execute it in batches, the memory is ever increasing.
I try to optimize go-wasm, but the effect is not good, the problem still exists.
Can you help me locate the cause?
Steps to reproduce
GOOS=js GOARCH=wasm go build -o main.wasm ./wasm/main.go
Expected behavior
I expect the memory usage to grown a bit and then even out to a stable number.
Actual behavior
The memory usage keeps increasing with invoke.
The text was updated successfully, but these errors were encountered: