Rick
Rick

Reputation: 1072

soundjs play potential memory leak by creating many WebAudioSoundInstance

If I continuously play a sound with soundjs in Chrome, there is an infinite increase of WebAudioSoundInstance count and therefore memory consumption grows.
How can one avoid it?

createjs.Sound.registerSound("audio/alarm.mp3", "alarm");

setInterval(function () {
 createjs.Sound.play("alarm");
}, 6500);

Screenshot of object instances

Upvotes: 1

Views: 281

Answers (2)

Aditya Nagrath
Aditya Nagrath

Reputation: 421

I have found a solution to this issue. Each time you play a sound it creates a webaudiosoundinstance, it also returns it, you could store it into a variable, and if the variable exists and is not null you can call play on that rather than calling the global function... this will keep your memory stable within the interval and does not require to unload and reload the sound.

Upvotes: 1

Rick
Rick

Reputation: 1072

For now I've found this dirty workaround:

var i = 0;
createjs.Sound.registerSound("audio/alarm.mp3", "alarm");

setInterval(function () {
    if (i == 10) {
        createjs.Sound.removeSound("alarm");
        createjs.Sound.registerSound("audio/alarm.mp3", "alarm");
        i = 0;
    }
    createjs.Sound.play("alarm");
    i++;
}, 6500);

Upvotes: 0

Related Questions