This repository explores memory management approaches in WebAssembly (Wasm) and Emscripten, focusing on convenience and minimal code in both C++ code compiled to WebAssembly and TypeScript.
The Emscripten SDK provides a rich set of tools for building, optimizing, and troubleshooting WebAssembly modules using C++. This repository demonstrates modern patterns for memory and resource management, focusing on interoperability between C++ and JavaScript. It also includes an example of using Clang’s AddressSanitizer to detect memory leaks and memory access errors. The full article is available at [].
- Configuring AddressSanitizer
- Returning data by value vs. by reference using Embind
- Taking advantage of the
usingclause for RAII-style automatic disposal - Implementing scope guards and Go-style
deferlogic - Handling JavaScript callbacks with exclusive memory ownership in WebAssembly
- Install Emscripten: Follow the official guide.
- Build examples: Run
npm run build. - Test: Run
npm test
Contributions are welcome! Please open issues or pull requests for new patterns or improvements.
MIT License. See LICENSE file for details.