Comments (6)
Ok this was fixed in the API redesign of #81, so I'm going to close this.
from wasmtime-go.
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:
- Rust has an instance in memory
- This instance has imported functions
- One imported function is a Go-defined function
- This Go-defined function closes over the Go instance
- The Go instance points to the Rust instance in memory
My recommendation would be to not close over Store-related objects and instead use Caller
if you can to access values. FWIW a similar problem exists in Rust if you create cycles manually as well.
from wasmtime-go.
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?
from wasmtime-go.
Yes unfortunately closing over a Memory
would also create a leak. As you've seen though the intended use case to fix this is to use Caller
to acquire the exported memory (or anything else if necessary). If an imported memory is reexported then that can be accessed, otherwise if it's only imported then you'll be able to close over it in the Go host function I think?
from wasmtime-go.
@alexcrichton thanks for the quick reply! I'll try out the re-export approach.
otherwise if it's only imported then you'll be able to close over it in the Go host function I think?
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.
from wasmtime-go.
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 Store
you'll cause a leak.
from wasmtime-go.
Related Issues (20)
- Is it possible to dynamically link several wasm modules in Go host? HOT 6
- Works with wit-bindgen? HOT 3
- Out of bounds memory access panic HOT 5
- Support for ARM macs with bazel
- Allocation too large< ~lib/rt/itcms.ts<$Index out of range,~lib/rt.ts HOT 4
- Add changelog/releases info HOT 1
- SetMaxWasmStack fails with async_stack_size error HOT 6
- Please elaborate on installation instructions for unsupported platforms HOT 1
- Does debugging work when embedding in go like rust? HOT 1
- Equivalence for `WasiCtx.insert_file` from wasmtime_wasi Rust crate HOT 14
- Minor release HOT 4
- Windows build failure: undefined reference to `_setjmp' HOT 7
- Error out when using wasmtime-go to run Python code HOT 2
- Compilation failure on 32-bit systems HOT 3
- How to monitor memory usage HOT 4
- Go get latest version failed
- Missing V15 features.component_model in config HOT 3
- Support v16? HOT 2
- Feature request: support manual freeing of resources HOT 2
- No compiled main function from file called HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasmtime-go.