Categories
JavaScript Answers

How to programmatically get memory usage in Chrome with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *