Maybe remove the not necessary `runtime.KeepAlive()`
howjmay opened this issue · comments
Yang Hau commented
According to this discussion https://forum.golangbridge.org/t/curious-about-runtime-keepalive-usage/3530, some common scenarios that need to call runtime.KeepAlive()
is
- you have obtained the file descriptor to an underlying os.File.
- you have passed memory to cgo which was allocated inside the same function.
In wasmtime-go, the variable that we are calling runtime.KeepAlive()
for are normally not allocated by the same function, so I think maybe we don't need runtime.KeepAlive()
?
Alex Crichton commented
Do you have some examples of invocations that can be removed? I tried to write things in such a way that removing any necessary call would trigger a panic, but it's also not guaranteed to panic so it's just a small safeguard.