Support disposable isolated instances without accumulating cached modules

Author: nuzzlesCreated Sep 22, 2026Updated Sep 22, 2026

We embed multiple Bevy/WASM canvases in one page using wasm-bindgen 0.2.125 (--target web). Unique import URLs (import bg.wasm?version=1) give each canvas an isolated instance, but every mount adds a cached JavaScript module that retains its WASM memory after unmount. A test retained 1, 2, then 3 memories after three mount/unmount cycles and forced GC, despite confirmed GPU device destruction and callback cleanup. Calling init() repeatedly on one imported module returns the same instance; blob-URL imports do not provide module unloading. This adds disposal evidence to #4888, #3130, #3407, and #3818. Is there a supported way to release an isolated instance after application teardown, without rewriting generated bindings or moving the renderer into a worker/iframe? The experimental reset work (#4665, #4909, #5059, #5083, #5099) looks[+] promising, but reset immediately allocates a replacement. I would like to clean up only.

Update: We tested the experimental reset using wasm_bindgen::handler::schedule_reinit() followed by another exported call. The generated reset uses synchronous new WebAssembly.Instance(...), which Chromium rejected for our approximately 29 MB release binary: “WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 8MB.” This also blocks reset-based reuse on our main thread; disposal without allocating a replacement remains the desired behavior.

Source: wasm-bindgen/wasm-bindgen