Skip to content

Commit 5d0ea64

Browse files
committed
AnimationManager.destroy now iterates through child animations calling destroy on all of them, avoiding a memory leak (thanks stauzs)
Animation.destroy didn't correctly clear the onStart, onLoop and onComplete signals.
1 parent a7f6165 commit 5d0ea64

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Version 2.0.4 - "Mos Shirare" - in development
6262
* TypeScript definitions fixes and updates (thanks @clark-stevenson)
6363
* Timer has removed all use of local temporary vars in the core update loop.
6464
* The Input.reset `hard` reset parameter is now passed down to the Keyboard and Key reset methods.
65+
* AnimationManager.destroy now iterates through child animations calling destroy on all of them, avoiding a memory leak (thanks stauzs)
6566

6667

6768
### New Features
@@ -80,6 +81,8 @@ Version 2.0.4 - "Mos Shirare" - in development
8081
* The main Timer loop could incorrectly remove TimeEvent if a new one was added specifically during an event callback (thanks @garyyeap, fix #710)
8182
* Fixed the use of the destroy parameter in Group.removeAll and related functions (thanks @AnderbergE, fix #717)
8283
* P2.World.convertTilemap now correctly checks the collides parameter of the tiles as it converts them.
84+
* Animation.destroy didn't correctly clear the onStart, onLoop and onComplete signals.
85+
8386

8487

8588
There is an extensive [Migration Guide](https://github.com/photonstorm/phaser/blob/master/resources/Migration%20Guide.md) available for those converting from Phaser 1.x to 2.x. In the guide we detail the API breaking changes and approach to our new physics system.

src/animation/Animation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ Phaser.Animation.prototype = {
386386
this.currentFrame = null;
387387
this.isPlaying = false;
388388

389-
this.onStart.destroy();
390-
this.onLoop.destroy();
391-
this.onComplete.destroy();
389+
this.onStart.dispose();
390+
this.onLoop.dispose();
391+
this.onComplete.dispose();
392392

393393
this.game.onPause.remove(this.onPause, this);
394394
this.game.onResume.remove(this.onResume, this);

src/animation/AnimationManager.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,23 @@ Phaser.AnimationManager.prototype = {
306306
},
307307

308308
/**
309-
* Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation.
309+
* Destroys all references this AnimationManager contains.
310+
* Iterates through the list of animations stored in this manager and calls destroy on each of them.
310311
*
311312
* @method Phaser.AnimationManager#destroy
312313
*/
313314
destroy: function () {
314315

316+
var anim = null;
317+
318+
for (var anim in this._anims)
319+
{
320+
if (this._anims.hasOwnProperty(anim))
321+
{
322+
this._anims[anim].destroy();
323+
}
324+
}
325+
315326
this._anims = {};
316327
this._frameData = null;
317328
this._frameIndex = 0;

0 commit comments

Comments
 (0)