Created
September 8, 2022 10:15
-
-
Save crmitchelmore/cebba87fd1419e4e9f5ae0047db8c967 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
function allocateMemory(size) { | |
// Simulate allocation of bytes | |
const numbers = size / 8; | |
const arr = []; | |
arr.length = numbers; | |
for (let i = 0; i < numbers; i++) { | |
arr[i] = i; | |
} | |
return arr; | |
} | |
const memoryLeakAllocations = []; | |
const field = "heapUsed"; | |
const allocationStep = 10000 * 1024; // 10MB | |
const TIME_INTERVAL_IN_MSEC = 40; | |
setInterval(() => { | |
const allocation = allocateMemory(allocationStep); | |
memoryLeakAllocations.push(allocation); | |
const mu = process.memoryUsage(); | |
// # bytes / KB / MB / GB | |
const gbNow = mu[field] / 1024 / 1024 / 1024; | |
const gbRounded = Math.round(gbNow * 100) / 100; | |
console.log(`Heap allocated ${gbRounded} GB`); | |
}, TIME_INTERVAL_IN_MSEC); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment