Quoting Store in wasmtime - Rust
A
Store
is intended to be a short-lived object in a program. No form of GC is implemented at this time so once an instance is created within aStore
it will not be deallocated until theStore
itself is dropped. This makesStore
unsuitable for creating an unbounded number of instances in it becauseStore
will never release this memory. It’s recommended to have aStore
correspond roughly to the lifetime of a “main instance” that an embedding is interested in executing.
Quoting wasmtime - Rust , the standard wasmtime setup looks something like:
let module = Module::new(&engine, wat)?;
let mut store = Store::new(&engine, 4);
let instance = Instance::new(&mut store, &module, &[host_hello.into()])?;
let hello = instance.get_typed_func::<(), (), _>(&mut store, "hello")?;
hello.call(&mut store, ())?;
So the problem here: based on the above quote, Store does not drop Instances when they are no longer in use. Therefore, if we try to build a REPL on Wasm, it is likely going to retain all old instances (code) as the REPL runs.
Is there a way to somehow avoid this? I would like to keep the "memory" associated with a Store, but drop all the Instance
(module code) when they are no longer in use.