-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak in Chrome - Error objects do not like to be persistent #9108
Conversation
…t, they seem to heavily capture variables they have in their scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a mention of this in the Changelog, as it is user-observable in theory.
Yeah, I think this was intended to be nicer to debug with, but I'm really not sure how specifically it helps. If it was important there would have been a test with it :)
Do you think this is related to #8571, or the linked Chrome bugs? |
It is possible, although it's hard to say without profiling - definitely worth a retest after this lands. |
emscripten-core#9108) * Fix memory leak in Chrome - Error objects do not like to be persistent, they seem to heavily capture variables they have in their scope. * Add comment in ChangeLog
…race attached Overrides Emscripten's default ExitStatus object which gets thrown on failure. Unfortunately, the default object is not a subclass of Error and does not provide any stack trace. This is a deliberate behavior on Emscripten's end to prevent memory leaks after the program exits. See: emscripten-core/emscripten#9108 In case of WordPress Playground, the worker in which the PHP runs will typically exit after the PHP program finishes, so we don't have to worry about memory leaks. As for assigning to a previously undeclared ExitStatus variable here, the Emscripten module declares `ExitStatus` as `function ExitStatus` which means it gets hoisted to the top of the scope and can be reassigned here – before the actual declaration is reached. If that sounds weird, try this example: ```js ExitStatus = () => { console.log("reassigned"); } function ExitStatus() {} ExitStatus(); // logs "reassigned" ```
…race attached (#470) ## Description Overrides Emscripten's default ExitStatus object which gets thrown on failure. Unfortunately, the default object is not a subclass of Error and does not provide any stack trace. This is a deliberate behavior on Emscripten's end to prevent memory leaks after the program exits. See: emscripten-core/emscripten#9108 In case of WordPress Playground, the worker in which the PHP runs will typically exit after the PHP program finishes, so we don't have to worry about memory leaks. As for assigning to a previously undeclared ExitStatus variable here, the Emscripten module declares `ExitStatus` as `function ExitStatus` which means it gets hoisted to the top of the scope and can be reassigned here – before the actual declaration is reached. If that sounds weird, try this example: ```js ExitStatus = () => { console.log("reassigned"); } function ExitStatus() {} ExitStatus(); // logs "reassigned" ``` ## Testing instructions Confirm the CI tests passed Related: #416 cc @wojtekn
…race attached (#470) ## Description Overrides Emscripten's default ExitStatus object which gets thrown on failure. Unfortunately, the default object is not a subclass of Error and does not provide any stack trace. This is a deliberate behavior on Emscripten's end to prevent memory leaks after the program exits. See: emscripten-core/emscripten#9108 In case of WordPress Playground, the worker in which the PHP runs will typically exit after the PHP program finishes, so we don't have to worry about memory leaks. As for assigning to a previously undeclared ExitStatus variable here, the Emscripten module declares `ExitStatus` as `function ExitStatus` which means it gets hoisted to the top of the scope and can be reassigned here – before the actual declaration is reached. If that sounds weird, try this example: ```js ExitStatus = () => { console.log("reassigned"); } function ExitStatus() {} ExitStatus(); // logs "reassigned" ``` ## Testing instructions Confirm the CI tests passed Related: WordPress/wordpress-playground#416 cc @wojtekn
Fix memory leak in Chrome - Error objects do not like to be persistent, they seem to heavily capture variables they have in their scope.
In Chrome, calling
var x = new Error();
in global scope causes an immediate capture of the scope, which leads inModule
being captured, along with.data
,.wasm
,.mem
etc. raw byte arrays, never reclaiming the memory.I don't think there's any pressing reason for ExitStatus to inherit from Error anyways? (was it due to convenience to get a pretty-printed error callstack?)