Skip to content

Instantly share code, notes, and snippets.

@rlucioni
Last active October 31, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlucioni/d2872b9e04ec30ce189f3c62c74462b4 to your computer and use it in GitHub Desktop.
Save rlucioni/d2872b9e04ec30ce189f3c62c74462b4 to your computer and use it in GitHub Desktop.
<!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