-
Notifications
You must be signed in to change notification settings - Fork 77
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 involving instances and WrapFunc (due to cycle?) #57
Comments
Thanks for the report! Unfortunately this is a difficult problem with no easy solution. As you've noticed there's a cycle between Rust's memory and Go's memory, concretetly:
My recommendation would be to not close over Store-related objects and instead use |
Right now the code that instantiates everything provides the memory as an import alongside those Go-defined functions. If the Go-defined functions close over that memory, I'm assuming that'll also create a cycle and we'll still see the leak. It looks like the Go-defined functions can get access to exported functions from the module via the Caller. Is it possible to also get access to the memory via the Caller? UPDATE: It looks like the Caller only provides access to exports. Would it be possible to extend the Caller to provide access to imported memory? |
Yes unfortunately closing over a |
@alexcrichton thanks for the quick reply! I'll try out the re-export approach.
Can you explain this a bit more? I don't see how the Go host function can close over the memory without creating a leak. |
Hm no you're right, I was mistaken. I'm thinking of a historical design of Wasmtime, but yeah nowadays if you close over anything connected to a |
Ok this was fixed in the API redesign of #81, so I'm going to close this. |
Hello!
I'm running into a memory leak in v0.22.0 after picking up the fix for #42. Here's a simple program that reproduces it:
This is a extension of the example from #42. The important difference is that the function passed to WrapFunc closes over the Instance because it's a member function of x. I think this creates a cycle that ultimately prevents the GC from calling the Instance finalizer.
I added some print statements into instance.go and func.go and confirmed that:
The text was updated successfully, but these errors were encountered: