Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Leak detection
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Memory Leak</title>
</head>
<body>
<h1>Memory Leak</h1>
<p>Click Start to run the script</p>
<button id="leak-button">Start</button>
<button id="stop-button">Stop</button>
<script>
let x = [];
let runing = false;
const leakButton = document.getElementById('leak-button');
const stopButton = document.getElementById('stop-button');
function grow(){
x.push(new Array(1000000).join('leak'));
if(running) {
setTimeout(grow, 1000)
}
}
leakButton.addEventListener('click', () => {
running = true;
grow();
});
leakButton.addEventListener('click', () => {
running = false;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment