Chrome dev utility - the first copy of the heap of memory, mysteriously large

I use the Profiles tab in the Chrome developer tools to record snapshots of a heap of memory. My application has a memory leak, so I expect that snapshots will gradually increase in size, which they do. But for reasons that I don’t understand, the first shot is always artificially large ... creating a seemingly deceptive memory fall between the first and second. All subsequent pictures are gradually enlarged as expected.

I know that at the beginning of page loading, extra memory is often used due to caching and other settings. But the same thing happens no matter when I take the first shot. This can be 30 seconds after the page loads or 30 minutes. The same picture. My only assumption is that the profile tool itself interacts with the memory in some way, but it looks like a stretch.

Any ideas what is going on here?

enter image description here

+5
source share
1 answer

Before taking a memory snapshot, Chrome tries to collect garbage. He does not collect it completely, although he has only a predetermined number of passes (this magic number seems 7 ). Therefore, when the first picture is taken, incorrect garbage can still be left.

Before taking the first shot, go to the Timeline tab and manually set the garbage collection.

Forced garbage collection in Chrome DevTools

From what I tested, it always reduces the size of the first snapshot.

Memory snapshots

+2
source

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


All Articles