The most functional tool in controlling JavaScript memory usage and finding leaks is the new powerful
Heap Profiler available in
Chrome Dev Channel. To get a heap snapshot, open the Profiles panel in Developer Tools and press the “Take heap snapshot” button:
Snapshots contain every object from the JavaScript heap, so you can explore them in detail and find out how much memory every object of your application consumes. The heap profiler also offers the following features:
- snapshots diffing
- grouping objects by constructor
- calculating retained sizes of objects
- showing dominators tree
- revealing paths to GC roots or window objects
In addition, the heap profiler takes into account native DOM nodes, and allows you to uncover DOM-related memory leaks.
It is also possible to measure how much JavaScript memory is currently used from within the page itself. You can sample values from the
performance.memory window property at different points of your application lifetime. Please note, that the property does not report anything, unless you run Chrome with
--enable-memory-info command-line argument.
For a more complete reference on working with the Chrome Developer Tools heap profiler, check out the
tutorial.