Sometimes, we want to programmatically get memory usage in Chrome with JavaScript.
In this article, we’ll look at how to programmatically get memory usage in Chrome with JavaScript.
How to programmatically get memory usage in Chrome with JavaScript?
To programmatically get memory usage in Chrome with JavaScript, we can use the window.performance.memory property.
For instance, we write:
console.log(window.performance.memory)
to log the current memory usage in Chrome.
As a result, we get something like:
{
"jsHeapSizeLimit": 2172649472,
"totalJSHeapSize": 6722851,
"usedJSHeapSize": 5630251
}
logged.
All the numbers are in bytes.
jsHeapSizeLimit is the maximum size of the heap that is available to the context.
totalJsHeapSize is current size of the JavaScript heap including free space not occupied by any JavaScript objects.
And usedJSHeapSize is the currently active segment of JS heap.
Conclusion
To programmatically get memory usage in Chrome with JavaScript, we can use the window.performance.memory property.