book
book copied to clipboard
Add a section about common memory management patterns between wasm and JS
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, withreturn 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?