Pappa Posted September 2, 2015 Share Posted September 2, 2015 Hi, I'm new to Phaser and I'm seeing an issue that looks like a memory leak, but I'm not sure if I'm using the onPlay Signal correctly. I'm using Phaser v2.4.3, and here's a simplified version of the code I'm working with:var PhaserGarbageTest = PhaserGarbageTest || {};PhaserGarbageTest.GameState = { init: function() { this.cursors = this.game.input.keyboard.createCursorKeys(); }, preload: function() { this.load.audio('splat', ['asset/audio/splat.mp3', 'asset/audio/splat.ogg']); }, create: function() { this.splatSound = this.add.audio('splat'); this.splatSound.onPlay.add(this.onSoundPlay, this); this.splatSound.onStop.add(this.onSoundStop, this); }, update: function() { if ((this.cursors.up.isDown || this.game.input.activePointer.isDown) && !this.splatSound.isPlaying) { this.splatSound.play(); } }, onSoundPlay: function (sound) { console.log("onSoundPlay"); }, onSoundStop: function (sound) { console.log("onSoundStop"); }};And here's the Chrome dev tools timeline recorded while I'm repeatedly playing the sound at short intervals, with a few small pauses: It seems that the listeners are being added to the document each time the sound is played. Can anyone shed some light on what I'm doing wrong? drhayes 1 Link to comment Share on other sites More sharing options...
Pappa Posted September 3, 2015 Author Share Posted September 3, 2015 Here's another Chrome timeline. This time over a longer period (140 seconds), and with about 250 onPlay callbacks being fired. Garbage collection is occurring as expected, giving me the standard sawtooth, but the listener count continues to rise until the Chrome timeline buffer is full. Link to comment Share on other sites More sharing options...
Pappa Posted September 7, 2015 Author Share Posted September 7, 2015 This seems to be caused by a memory leak in Phaser.Sound. A reference to the AudioBufferSourceNode is kept hanging around. I have been able to fix it by modifying Phaser.Sound.prototype.onEndedHandler: onEndedHandler: function () { this._sound.onended = null; this.isPlaying = false; this.stop(); }, drhayes 1 Link to comment Share on other sites More sharing options...
drhayes Posted September 8, 2015 Share Posted September 8, 2015 Are you going to submit a pull request to fix the bug? Link to comment Share on other sites More sharing options...
Pappa Posted September 8, 2015 Author Share Posted September 8, 2015 I just did. drhayes 1 Link to comment Share on other sites More sharing options...
rich Posted September 8, 2015 Share Posted September 8, 2015 And I just merged it Nice one. drhayes 1 Link to comment Share on other sites More sharing options...
Pappa Posted September 9, 2015 Author Share Posted September 9, 2015 My first Github pull request. drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts