Comments (4)
That sounds good. Can we close this then? Please feel free to reopen it if you have any remaining concerns. Thanks!
from emscripten.
Regarding the memory leak issue specifically, I don't think that the incrementExceptionRefcount
/decrementExceptionRefcount
calls are going to recover you stack memory. For one thing, I believe these function deal with heap allocations, not stack allocations, and also there could be any number of other data structure that are on the stack when the exception is thrown.
When you catch a native exception from JS I think its incumbent upon you to restore the stack pointer before calling back into Wasm. You can do this by calling var sp = stackSave()
before the try
and then stackRestore(sp)
in the catch block. @aheejin correct me if I'm wrong here.
from emscripten.
So it looks the exception is allocated on the stack first, and then copied when thrown, because it is thrown by value. And what JS catches is that copied exception. So increment/decrementExceptionRefcount
takes care of freeing the caught (=copied) exception, but not the original stack-allocated one. I think, as @sbc100 suggested, you should use stackSave
and stackRestore
to restore the stack, like this: #17313 (comment) (Nevermind the other stuff; only the uses of the two methods are relevant here.)
And we should probably consider adding that to the documentation, because it is easy to miss.
Also test_EXPORT_EXCEPTION_HANDLING_HELPERS
is being tested both for Emscripten EH and Wasm EH, so your error is strange. It's hard to reproduce the error by reading your build script. Can you give me a command line reproducer and the source files that produces the export error?
from emscripten.
Thanks very much for your responses! Manipulating the stack pointer is a game I'd rather not play, so I decided to add some C++ code to my Emscripten bindings to catch all exceptions before they exit WebAssembly and instead convert them into normal return values as { result }
or { error }
objects for the JavaScript caller. This change has resolved my memory leak.
from emscripten.
Related Issues (20)
- Any example to compile a project via emscripten and use it in wasmtime? HOT 10
- In `-sMODULARIZE` mode the `moduleArg` should not be modified in place
- Bind error of getting a pointer property in class
- Make mimalloc headers accessible HOT 2
- lto2.test_embind_i64_val is failing
- evaluation of std::sin in C++ is slower than in JS directly HOT 3
- [CXX1429] error when building with cmake using HOT 1
- Bug: when compiling executable, emcc "forgets" provided needed library HOT 8
- [WASMFS] FileSystemHandle.move causes OPFS to fail in Chrome HOT 1
- NODEFS not compatible with Deno when used through Pyodide HOT 4
- Unification for async APIs for the header file emscripten.h
- Unification for async APIs for the header file HTML5.h
- Unification for async APIs for the header file proxying.h
- Unification for async APIs for the header file Val.h
- Unification for async APIs for the header file Fetch.h
- Unification for async APIs for the header file webaudio.h
- 256-bit AVX intrinsics support HOT 1
- 'emcc' is not recognized as an internal or external command, operable program or batch file. HOT 2
- Multiple main function definitions can cause runtime error in chrome and crash renderer process in electron HOT 8
- Cannot convert 1698917542 to a BigInt HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emscripten.