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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Leak</title> | |
</head> | |
<body> | |
<button id="allocate">Allocate</button> | |
<button id="release">Release</button> | |
<script> | |
const allocate = document.getElementById("allocate"); | |
const release = document.getElementById("release"); | |
let strings = []; | |
let interval; | |
randomInteger = (min, max) => { | |
// Min is inclusive, max is exclusive. | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} | |
storeString = (size) => { | |
const s = new Array(size).join('s') | |
strings.push(s); | |
} | |
leak = () => { | |
// Allocate 1-3 MB. | |
const size = randomInteger(1e6, 3e6); | |
storeString(size); | |
} | |
allocate.onclick = () => { | |
interval = setInterval(leak, 500); | |
}; | |
release.onclick = () => { | |
clearInterval(interval); | |
strings = []; | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment