My question is similar to Do local variables inside of a loop get garbage collected?
I have a class that uses recursion to play a blip sound effect in a typewriter style character dialogue screen:
class DialogueBox extends Component{
constructor(props){
super(props)
this.state = {...
}
...
}
typeWriter(txt,i,speed=50) {
if(i==txt.length){
...
return
}
else{
// a blip sound effect plays on every new character typed
let sfx = new Audio(speechBlip);
sfx.play();
...
setTimeout(()=>this.typeWriter(txt,i+1,speed),speed);
}
}
Note the local variable let sfx = new Audio(speechBlip)
that is being instantiated multiple times. Will this result in a ton of Audio objects stored in memory that will never be cleaned up?
I'm using this method because I like how it sounds more than creating one Audio() in the constructor and re-setting it to 0 time or only replaying when the file completes playing.
Would this method be a major drag on memory? I tried using the memory panel of dev tools but I am not sure if I am interpreting it correctly and am unsure about how it will scale...