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:
Repeatedly calling setContext with the same native AudioContext creates undisposed unused Tone Contexts.
Repeatedly calling
myContext = new AudioContext();
Tone.setContext(myContext);
myContext.close();
does the same.
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.
This makes it harder to introduce a resource leak.
This is especially useful when you pass native
AudioContext
tosetContext
. Consider these examples, where it doesn't look like there are any memory leaks, but actually there are:setContext
with the same nativeAudioContext
creates undisposed unused ToneContext
s.does the same.
It looks to me like a real solution would be to make
setContext
only acceptBaseContext
, shifting the burden of creating and disposing ToneContext
/OfflineContext
to the user, but that would be breaking. ThedisposeOld
parameter could perhaps also be preserved.I only ran
test:html
.