Created
January 30, 2020 12:54
-
-
Save LaleWolf/51cf9be735c33a946bc2a9ede0d9f37e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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