Skip to content

Instantly share code, notes, and snippets.

@LaleWolf
Created January 30, 2020 12:54
Show Gist options
  • Save LaleWolf/51cf9be735c33a946bc2a9ede0d9f37e to your computer and use it in GitHub Desktop.
Save LaleWolf/51cf9be735c33a946bc2a9ede0d9f37e to your computer and use it in GitHub Desktop.
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<body></body>`);
const document = dom.window.document;
const runnerLoopCount = 10;
const canvasLoopCount = 1000;
const newJSDomOnlyFabricCanvas = () => {
for (let i = 0; i < canvasLoopCount; i++) {
const docCanvas = document.createElement('canvas');
const ctx = docCanvas.getContext('2d');
ctx.rect(100, 100, 100, 50);
}
};
const logMemoryUsage = () => {
let usage = process.memoryUsage()
console.log("{ rss: %d,\theapTotal: %d,\theapUsed: %d,\texternal: %d }", usage.rss, usage.heapTotal, usage.heapUsed, usage.external);
};
const runner = () => {
logMemoryUsage();
for (let i = 0; i < runnerLoopCount; i++) {
newJSDomOnlyFabricCanvas();
if (global.gc) {
global.gc();
}
logMemoryUsage();
}
};
//start memory leak loop
runner();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment