Add a section about common memory management patterns between wasm and JS
#79 opened on Aug 23, 2018
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
asyncversion 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?