Skip to content

Instantly share code, notes, and snippets.

@krishnathota
Last active October 22, 2021 08:45
Show Gist options
  • Save krishnathota/41a3807c23077c8bbb73cd0d04624027 to your computer and use it in GitHub Desktop.
Save krishnathota/41a3807c23077c8bbb73cd0d04624027 to your computer and use it in GitHub Desktop.
Finding JS memory usage of a chrome tab
var div = document.createElement('div');
div.style.cssText = 'position:absolute;top:0;right:0;background:rgba(255,255,255,0.7);padding:10px;pointer-events:none;z-index:10000;font-weight:bold;font-size:20px';
document.body.appendChild(div);
setInterval(function () {
div.innerHTML = (Math.round(console.memory.usedJSHeapSize / 1024 / 1024 * 10) / 10) + ' / ' + (Math.round(console.memory.totalJSHeapSize / 1024 / 1024 * 10) / 10);
gc();
}, 250);
Add the below flags while running chrome
--enable-precise-memory-info --js-flags="--expose-gc"
Ex:
"C:\Program Files\Google\Chrome Beta\Application\chrome.exe" --user-data-dir="C:/ChromeDevSession" --disable-web-security --ignore-certificate-errors --enable-precise-memory-info --js-flags="--expose-gc"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment