book icon indicating copy to clipboard operation
book copied to clipboard

Add a section about common memory management patterns between wasm and JS

Open fitzgen opened this issue 5 years ago • 0 comments

This would be a new reference sub-section.

Things to mention:

  • [ ] Dynamically allocated objects owned by JS must be manually freed by JS

  • [ ] To help alleviate that pain, mention the JS equivalent of RAII:

    function withResource(f) {
        let resource = new Resource();
        try {
            return f(resource);
        } finally {
            resource.free();
        }
    }
    

    also the async version of that, with return await f(resource);

  • [ ] Static globals in rust that don't need to have their lifetime managed by JS

  • [ ] Mention upcoming GC weakrefs, link to tracking page, explain their relevance to cleaning up objects in wasm

  • [ ] Mayyyybe mention how one could build reference counting in JS of dynamically allocated wasm objects? I don't know of anyone actually doing this, so maybe not mention it until then?

Anything else?

fitzgen avatar Aug 23 '18 22:08 fitzgen