memlab
memlab is an E2E testing and analysis framework for finding memory leaks
in-browser JavaScript Code. The CLI Toolbox and library provide extensible
interfaces for analyzing heap snapshots taken from Chrome, Node.js, Hermes,
and Electron.js.
CLI Usage
Install the CLI
npm install -g @memlab
Find memory leaks in Google Maps:
wget -q -O test-google-maps.js https://tinyurl.com/4yr5watu
memlab run --scenario test-google-maps.js
View which object keeps growing in size during interaction in the previous run:
memlab analyze unbound-object
Analyze pre-fetched v8/hermes .heapsnapshot
files:
memlab analyze unbound-object --snapshot-dir <DIR_OF_SNAPSHOT_FILES>
Use memlab analyze
to view all memory analyses. For extension, view the doc site.
View retain trace of a particular object:
memlab report --nodeId <HEAP_OBJECT_ID>
Use memlab help
to view all CLI commands.
APIs
Use the memlab
library to start a E2E run in browser and detect memory leaks.
const memlab = require('memlab');
const scenario = {
url: () => 'https://www.google.com/maps/@37.386427,-122.0428214,11z',
action: async (page) => await page.click('button[aria-label="Hotels"]'),
back: async (page) => await page.click('[aria-label="Clear search"]'),
}
memlab.run({scenario});