Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mohayonao/fd25c883f17ddeb365e2a8725e036d2f to your computer and use it in GitHub Desktop.

Select an option

Save mohayonao/fd25c883f17ddeb365e2a8725e036d2f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>memory leak</title>
</head>
<body>
<button id="test">test</button>
<div id="debug"></div>
<script src="build/web-audio-engine-old.js"></script>
<script>
window.addEventListener("DOMContentLoaded", () => {
"use strict";
var audioContext = new WebAudioEngine.WebAudioContext({ context: new AudioContext() });
var $debug = document.getElementById("debug");
function beep() {
var t0 = audioContext.currentTime;
var t1 = t0 + 0.05;
var oscillator = audioContext.createOscillator();
var gain = audioContext.createGain();
oscillator.start(t0);
oscillator.stop(t1);
oscillator.connect(gain);
gain.gain.value = 0;
gain.connect(audioContext.destination);
}
document.getElementById("test").addEventListener("click", () => {
var counter = 0;
$debug.textContent = "RUNNING";
function loop() {
beep();
counter += 1;
if (counter < 10000) {
setTimeout(loop, 0);
} else {
$debug.textContent = "END";
}
}
loop();
});
audioContext.resume();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment