Search code examples
javascriptperformancegoogle-chromememory-leaks

Chrome usedJSHeapSize property


First of all, I've looked around the internet and found it quite badly documented. Somewhere in my code I have a big memory leak that I'm trying to track and after using:

window.performance.memory.usedJSHeapSize 

it looks like the value remains at the same level of 10MB, which is not true because when we compare to the values either visible here:

chrome://memory-internals/

or if we look at the Timeline in devTools we can see a big difference. Does anyone encountered a similar issue? Do I need to manually update these values (to run a command "update", "measure" etc?)

Following this topic: Information heap size it looks like this value is increased by a certain step, can we somehow see what is it or modify it? In my case from what I can see now the page has about 10MB, 30 minutes later there will be about 400MB, and half an hour after the page will crash.. Any ideas guys?

(Why the code is leaking it's a different issue, please treat this one as I was trying to use this variable to create some kind of test).


Solution

  • There's a section of the WebPlatform.org docs that explains this:

    The values are quantized as to not expose private information to attackers. If Chrome is run with the flag --enable-precise-memory-info the values are not quantized.

    https://webplatform.github.io/docs/apis/timing/properties/memory/

    So, by default, the number is not precise, and it only updates every 20 minutes! This should explain why your number doesn't change. If you use the flag, the number will be precise and current.

    The WebKit commit message explains:

    This patch adds an option to expose quantized and rate-limited memory
    information to web pages. Web pages can only learn new data every 20
    minutes, which helps mitigate attacks where the attacker compares two
    readings to extract side-channel information. The patch also only
    reports 100 distinct memory values, which (combined with the rate
    limits) makes it difficult for attackers to learn about small changes in
    memory use.