I have an ambient music generating web audio app - http://christopheralcock.github.io/falling3rds/ - which creates lots of audiocontext nodes to make a constantly evolving, fairly relaxing, musical texture.
After about 100 seconds, though, there are too many nodes and garbage collection kicks in and makes horrible, unrelaxing clicking noises and ruins everything.
I could rewrite the software so that it creates fewer nodes, but don't want to if I don't have to, not least because I think the actual effect would be end up different.
What I want is to destroy each (oscillator etc) node about 30 seconds after they're created, stopping the node-count from ever getting into the hundreds.
The code is here, fwiw: https://github.com/christopheralcock/falling3rds/tree/gh-pages
Thanks
Have just come across this again and thought I may as well answer with what I did in the end to fix it, within the paradigm set out in the question:
I used the AudioNode.disconnect() method: https://developer.mozilla.org/en-US/docs/Web/API/AudioNode/disconnect
I used setTimeout and an arbitrary period of time when nodes were created and connected. Then after the time period they would be disconnected. Then when garbage collection takes place, it's just clearing up disconnected nodes, which doesn't make noise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With