Chrome memory leak. How to debug at startup Javascript Profiler Fixes a leak?

I am making a game using canvas and am in weird Chrome behavior that I cannot commit. Sometimes, when I download a game, the Chrome Task Manager reports that it allocates + 300 MB per second, increasing to a few GB of memory in just 10 seconds or so, and it does not stop until the tab stops.

When I try to run the javascript profiler, the problem stops. When I load the tab with the launch of the profiler, it is absolutely stable. When a problem occurs, and then I start the profiler, it will go from 1.5 GB to a stable 40 MB right away. And a heap shot shows me what I expect if the game is stable.

My game works on window.setInterval(I tried requestAnimationFrameand recursive setTimeout, and the problem still happens), and it happens more often when it is set high, which means that when I install the game at 30FPS, it rarely happens, and when I install it at 60FPS, this happens in half the cases. This only happens in Chrome, Firefox seems great.

How to debug this when Chrome seems to do garbage collection only when the profiler starts?

In addition, I noticed that some of my animations and keyboard input are a little funny when I press FPS on 60. I assume this may be related, but this also takes place in Firefox.

+4
source share
3

JavaScript , , , ( setTimeout/rAF, ..), ..

( ), , GC - Chrome Firefox, ( , ). , , .

, FPS, , .. , , , - GC "" , ( ). , .

, , , // .

( , ), , , ..

- , , .

:

function loop() {

    var startTime = performance.now();

    ... other code ...

    var innerLoopTime = performance.now() - startTime;

    requestAnimationFrame(loop);
}

60 FPS, 1000/60 16,667 .

innerLoopTime , , , , .

, , . , . , , .

+5

, javascript- closures. setInterval, ​​, , , - . , , .

js , IBM , , , .

+2

We noticed that chrome + canvas is not as effective as firefox + canvas. As for the GC, when you open the chrome dev tools, I would suggest that you might have some kind of code that pushes the chrome in the correct order to make the GC. Do you have any window resizing handler? Maybe something else that does something like this.

If in doubt, split the code in half until this happens again.

+1
source

Source: https://habr.com/ru/post/1539633/


All Articles