bytecodealliance/wasmtime-go

Maybe remove the not necessary `runtime.KeepAlive()`

howjmay opened this issue · 1 comments

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

  1. you have obtained the file descriptor to an underlying os.File.
  2. 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()?

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.