In a web application which loads large amount of data crashes when it exceeds a certain limit. So i want to find the memory used by a chrome tab using javascript ie by code to prevent this sort of problem.
Press Shift+Esc or go to the Chrome main menu and select More tools > Task manager to open the Task Manager. Right-click on the table header of the Task Manager and enable JavaScript memory. These two columns tell you different things about how your page is using memory:
For this browser, there was always a keyboard shortcut available in the form of ‘Shift+Esc’ to display and monitor the memory usage by Chrome extensions and browser tabs in the Google Chrome Task Manager window.
The Memory panel of the Chrome Developer Tools provides information about how a page is using memory. If you notice that your website has become slower, a memory leak should be considered as a possible cause. Chrome Memory tab is designed for solving memory issues, including debugging of JavaScript memory leaks.
Protip: if you open the same page in IE, FF, Safari... and Chrome; and than navigate to about:memory in Chrome, it will report memory usage across all other browsers. Neat!
here from the source code of the chrome:
// Make the values returned to window.performance.memory more granular and more up to date in shared worker. Without this flag, the memory information is still available, but it is bucketized and updated less frequently. This flag also applys to workers. const char kEnablePreciseMemoryInfo[] = "enable-precise-memory-info";
So you need the --enable-precise-memory-info
flag to get a more dynamic and accurate result. For security reasons, Google Chrome doesn't provide precise information via performance.memory
by default. You can see here https://github.com/paulirish/memory-stats.js/tree/master a good way to monitor the memory. But this is not a good solution even if you have control over the way the user runs the "site". You can't be sure where Chrome will crash or how accurate is the data.
A first solution would be to make a global factory pattern that counts all the new objects and have some predefined size for each and when the size reaches a certain number you can alert the user. Be careful in that way you don't count the bound events. You can try and add the events in the same factory (or better another) but I don't know how accurate this will be.
A second solution, and better solution is this example. A great example, with 500,000 records with fast response and low memory. How? Easy, just load the data the user sees and nothing else. When the user scrolls it finds the right data without loading all the rest. That's something you can do with something that take many memory.
We recently faced same problem.
You can use web performance API for to check current total memory allocation.
window.performance
It allows web pages to access to certain functions for measuring the performance of web page. There is a non-standard extension available only for chrome to record memory information.
window.performance.memory
It will return you following information.
usedJsHeapSize
: total amount of memory being used by JS objects including V8 internal objects,totalJsHeapSize
: current size of the JS heap including free space not occupied by any JS objectsAlso there is a js library available for recording memory stats. (https://github.com/spite/memory-stats.js)
Please checkout this as well. It might help you. - https://developer.chrome.com/devtools/docs/javascript-memory-profiling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With