rustwasm/book

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

Open

#79 opened on Aug 23, 2018

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Handlebars (215 forks)auto 404
enhancementhelp wanted

Repository metrics

Stars
 (1,832 stars)
PR merge metrics
 (PR metrics pending)

Description

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?

Contributor guide