You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"flag""rogchap.com/v8go"
)
funcno_mem_leak() {
iso, _:=v8go.NewIsolate() // creates a new JavaScript VMctx1, _:=v8go.NewContext(iso) // new context within the VMctx1.RunScript("const multiply = (a, b) => a * b", "math.js")
ctx2, _:=v8go.NewContext(iso) // another context on the same VMfori:=0; i<1000000000; i++ {
if_, err:=ctx2.RunScript("multiply(3, 4)", "main.js"); err!=nil {
// this will error as multiply is not defined in this context
}
}
}
funcmem_leak() {
iso, _:=v8go.NewIsolate() // creates a new JavaScript VMctx, _:=v8go.NewContext(iso) // new context within the VMctx.RunScript("const multiply = (a, b) => a * b", "math.js")
fori:=0; i<1000000000; i++ {
if_, err:=ctx.RunScript("multiply(3, 4)", "main.js"); err!=nil {
// this will error as multiply is not defined in this context
}
}
}
funcmain() {
memLeakFlag:=flag.Bool("mem_leak", false, "mem_leak")
flag.Parse()
if*memLeakFlag {
mem_leak()
} else {
no_mem_leak()
}
}
When I called RunScript on same context, a possible memory leak problem may happen. Is this a bug? Or I used the context in a wrong way?
The above code is what I have run. And the memory:
The text was updated successfully, but these errors were encountered:
This is the same memory leak as #105, although the title of that makes it sound like a more limited.
What is happening is that v8go keeps a reference to all v8go.Value objects that it creates, including the one returned from RunScript. This memory is held onto until the isolate is disposed.
When I called
RunScript
on same context, a possible memory leak problem may happen. Is this a bug? Or I used the context in a wrong way?The above code is what I have run. And the memory:
The text was updated successfully, but these errors were encountered: