Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.52k stars 983 forks source link

improvement: add `disposeOld` parameter to `setContext` #880

Closed WofWca closed 3 years ago

WofWca commented 3 years ago

This makes it harder to introduce a resource leak.

This is especially useful when you pass native AudioContext to setContext. Consider these examples, where it doesn't look like there are any memory leaks, but actually there are:

It looks to me like a real solution would be to make setContext only accept BaseContext, shifting the burden of creating and disposing Tone Context/OfflineContext to the user, but that would be breaking. The disposeOld parameter could perhaps also be preserved.

I only ran test:html.