Created
July 30, 2024 19:07
-
-
Save EduardoRFS/5837a3145a7b5c2333319eeaa0284e22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 printOnce = function (data) { | |
let printed = false; | |
return function () { | |
if (!printed) { | |
console.log(data.byteLength); | |
} | |
printed = true; | |
}; | |
}; | |
function demo() { | |
const bigArrayBuffer = new ArrayBuffer(100_000_000); | |
for (let i = 0; i < bigArrayBuffer.byteLength; i++) { | |
bigArrayBuffer[i] = 0; | |
} | |
const trigger = printOnce(bigArrayBuffer); | |
return trigger; | |
} | |
globalThis.triggerDemo = demo(); | |
globalThis.triggerDemo(); | |
globalThis.triggerDemo(); // noop, but memory is still reachable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment