Code Monkey home page Code Monkey logo

Comments (6)

alexcrichton avatar alexcrichton commented on June 15, 2024 1

Ok this was fixed in the API redesign of #81, so I'm going to close this.

from wasmtime-go.

alexcrichton avatar alexcrichton commented on June 15, 2024

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.

tsandall avatar tsandall commented on June 15, 2024

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.

alexcrichton avatar alexcrichton commented on June 15, 2024

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.

tsandall avatar tsandall commented on June 15, 2024

@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.

alexcrichton avatar alexcrichton commented on June 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.