Skip to content
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

Memory grows each time the page refresh until error appear : Uncaught RangeError: WebAssembly.Memory(): could not allocate memory #8126

Open
pierreglibert opened this issue Feb 19, 2019 · 25 comments

Comments

@pierreglibert
Copy link

pierreglibert commented Feb 19, 2019

Hi community :)
I get an error after several refresh : Uncaught RangeError: WebAssembly.Memory(): could not allocate memory.

When I go to "inspect > memory > Select Javascript VM instance", memory grows each time I refresh the page.
When memory is bigger than 40mo, the error appear.
How can I clear memory on refresh page ?
The memory should not be deleted automatically ?

My code :
`extern "C" {

void EMSCRIPTEN_KEEPALIVE gl() {
    
    // set size of viewport
    glViewport(0, 0, 800, 600);
    
}

int EMSCRIPTEN_KEEPALIVE main() {
    // insert code here...
    emscripten_log(EM_LOG_CONSOLE, "hello world \n");
    return 0;
};

}`

My terminal cmd :
main.cpp -Os -std=c++17 -s USE_WEBGL2=1 -o main.html

Thanks in advance for your help ;)

@pierreglibert pierreglibert changed the title Memory grows each time the page refresh : Uncaught RangeError: WebAssembly.Memory(): could not allocate memory Memory grows each time the page refresh until error appear : Uncaught RangeError: WebAssembly.Memory(): could not allocate memory Feb 19, 2019
@kripken
Copy link
Member

kripken commented Feb 21, 2019

The browser should clear the memory, but may take time until it garbage collects it. So this could be a browser bug, or at least something the browser could do better. Which browser is it on? We should file a bug with a testcase.

@GoJermangoGo
Copy link

I'm getting the same problem on Chrome 72 Linux with the latest Ammo build. After 36 refreshes (probably arbitrary, but in my project it's always the same number) I get the error:

Uncaught RangeError: WebAssembly.Memory(): could not allocate memory
    at ammo.wasm.js:formatted:175
    at main ((index):82)
    at onload ((index):17)

Which is just the memory module constructor:

new WebAssembly.Memory({
    initial: Aa / 65536,
    maximum: Aa / 65536
})

Looking into a heap snapshot shows the full story:

Chrome isn't fully resetting the heap! Clicking the garbage collection button doesn't help, either. Firefox doesn't have this issue so it's probably just a Chrome bug. It's also worth noting that I can't get the same effect when manually creating a memory object in the console.

@pierreglibert
Copy link
Author

pierreglibert commented Feb 24, 2019

@luisfonsivevo @kripken thanks for your reply :)

I'm on macOs 10.14.3, google chrome 72.0.3626.109.
I'm agree with you, firefox work fine. It's a chrome bug.

Chrome capture :
capture d ecran 2019-02-24 a 10 23 29
capture d ecran 2019-02-24 a 10 24 27

Where can we create an issue for google chrome ?
Edit : I report the problem with : Help > Report an issue.

@GoJermangoGo
Copy link

@pierreglibert Here's a link to Chromium's official bug tracker

@pierreglibert
Copy link
Author

@luisfonsivevo done :)

@pierreglibert
Copy link
Author

... I have this with firefox, but memory does not seem to grow : �
capture d ecran 2019-02-24 a 16 24 21

It show "exceeded 16 live ..." exactly after 16 page refreshes...

@kripken
Copy link
Member

kripken commented Feb 25, 2019

@pierreglibert do you have a link to the bug you filed? I can try to cc some relevant people to speed things up.

@pierreglibert
Copy link
Author

Last test :
• Safari 12.0.3 works 👍
• Opera 58.0.3135.68 works 👍
• Firefox 65.0.1 works BUT show warning after 16 refresh 👎

Error: WebGL warning: : Exceeded 16 live WebGL contexts for this principal, losing the least recently used one.

• Chrome 72.0.3626.119 works BUT show error after several refresh 👎

Uncaught RangeError: WebAssembly.Memory(): could not allocate memory

@kripken
Copy link
Member

kripken commented Feb 25, 2019

Thanks @luisfonsivevo! Looks like it's already being prepared for triage, good.

@pierreglibert
Copy link
Author

Here a sample :
triangle.zip

@pierreglibert
Copy link
Author

pierreglibert commented Mar 6, 2019

I played around with this some more and found that it only happens when DevTools is open. Once I close DevTools I can refresh the page as normal and the memory is properly freed. Memory won't start growing again until DevTools reopens and the page is refreshed.

I confirm, it's only appear when devTool is open.
Thanks @Jerbear.

google issue

@mmontag
Copy link
Contributor

mmontag commented Mar 8, 2019

Wow, another confirmed case here.
I started to go crazy walking back changes to my build before I finally Googled this error. Good work @pierreglibert

@iooops
Copy link

iooops commented Mar 31, 2019

Is there any way to solve it?

@GoJermangoGo
Copy link

Currently the only way to fix this (in Chromium) is to close dev tools and then refresh the page. Normal users won't have a problem because this bug is only related to dev tools. Still not fixed yet as of 73.

As for for Firefox, I haven't been able to reproduce it.

@nicksen782
Copy link

nicksen782 commented Apr 5, 2019

I also encounter this issue at the 36th load and it is consistent. However, I encounter it with or without Dev tools open. This is the loading portion of my program where I start each instance. (I last updated my copy of Emscripten on 2019-03-22.)

// Remove the Module.
emu.vars.innerEmu.Module=null;

// Wait 500 ms.
setTimeout(function(){
// Reset Module to the defaults settings.
emu.vars.innerEmu.Module = new emu.vars.innerEmu.createDefaultModule();

// Edit Module: Set the game file.
emu.vars.innerEmu.Module.arguments = [emu.vars.gameFile];

try{
// Start the new instance.
emu.vars.innerEmu.UOP( emu.vars.innerEmu.Module );
}
catch(e){ console.log("The emulator failed to load. Please refresh this web page.", e); }
}, 500);

-- Edit below:
That was with Web Assembly and here is the error: WebAssembly.Memory(): could not allocate memory
at Object.UOP (emu_core_WASM.js:8)
at emu.js:1038
Emulator loads : 36, jsHeapSizeLimit: 2,181,038,080, totalJSHeapSize: 625,122,679, usedJSHeapSize : 610,854,991

I used ASM.JS and loaded 100 times. The memory usage continued to climb (still a problem) but the app did not crash.
Emulator loads : 100, jsHeapSizeLimit: 2,181,038,080, totalJSHeapSize: 1,712,296,646, usedJSHeapSize : 1,696,293,454

@vanjavk
Copy link

vanjavk commented Jun 20, 2019

Bug is still present (I use webgl2 in my files). Simple triangle drawing.

Last test :
• Safari 12.0.3 works 👍
• Opera 58.0.3135.68 works 👍
• Firefox 65.0.1 works BUT show warning after 16 refresh 👎

Error: WebGL warning: : Exceeded 16 live WebGL contexts for this principal, losing the least recently used one.

• Chrome 72.0.3626.119 works BUT show error after several refresh 👎

Uncaught RangeError: WebAssembly.Memory(): could not allocate memory

For me this is incorrect.
It doesn't work either in current latest Chrome❌ (>than your version) and Opera❌(>than your version). Which would make sense because Opera is based on Chromium.

However in Firefox it works fine.
Firefox: 67.0.4 (64-bit) ✔

(I do get "Error: WebGL warning: : Exceeded 16 live WebGL contexts for this principal, losing the least recently used one." warning however it still loads fine unlike Opera and Chrome where it fails to load completely.

After every refresh snapshot says memory is about same and is not increasing. Unlike on both chrome and opera where after about 30 refreshes memory reaches certain amount (seems to be 600MB?) and doesn't want to load anymore

@kripken
Copy link
Member

kripken commented Jun 20, 2019

There are some known issues with the chrome devtools and with pthreads on chrome. If this isn't related to either of those, then a testcase would be good, as this may be an unknown bug.

@vanjavk
Copy link

vanjavk commented Jun 21, 2019

Actually this seems to be a problem with chrome devtools for me. If I close and reopen devtools memory is reset, and app is loading fine. (Too bad I didn't see luisfonsivevo comment before)

I also wasn't able to reproduce this bug when not using chrome devtools.

@Fercho120
Copy link

Same issue here: I've got an WebAssembly.Memory(): could not allocate memory error after refreshing a page that imports and initializes a quite heavy webassembly module (Opencv.js); I'm using Chrome 76.0.3809.100

@pierznj
Copy link

pierznj commented Sep 25, 2019

Aaaand one more here, also using Opencv.js (with Chrome 77.0.3865.90).

@DoubleCorner
Copy link

Same issue here: I've got an WebAssembly.Memory(): could not allocate memory error after refreshing a page that imports and initializes a quite heavy webassembly; I'm using Chrome 78.0.3904.108

@kripken
Copy link
Member

kripken commented Dec 11, 2019

As mentioned a few comments back: there are known issues with devtools, and known issues with pthreads (although I think the pthreads ones were fixed in latest stable). If you see this without either of those, then please provide a testcase, as that may be an unknown issue.

@Junior2Ran
Copy link

Chrome 83,still not fixed.
Is there a way that I can free the memory by hand? Like memeory.destory() or something?

@JuniorTour
Copy link

Win 10 && Chrome 92, still has this error: WebAssembly.Memory(): could not allocate memory

Does it relate to SharedArrayBuffer was removed from Chrome API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests