Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite Animations are not removed completely. #1449

Closed
Arturszott opened this issue Dec 12, 2014 · 4 comments
Closed

Sprite Animations are not removed completely. #1449

Arturszott opened this issue Dec 12, 2014 · 4 comments

Comments

@Arturszott
Copy link

There is a problem with memory leak. When you will add looped animation to the sprite, it somehow holds the sprite in memory after using sprite's destroy method preventing garbage collector to free the memory.

@photonstorm
Copy link
Collaborator

Can you prove this through with a profile dump / timeline evidence please.

@Arturszott
Copy link
Author

@photonstorm
Copy link
Collaborator

I have added in some extra checks and reference clearing in the dev branch, so if you could build and test against that it'd be good thanks

@photonstorm
Copy link
Collaborator

Ok I tested this against 2.3-dev. The example I used creates 1 new looped animated sprite every 50ms. I let it run until it had destroyed 2500 sprites and checked the memory profile in dev tools and it was fine - a bit of gc every 30 seconds or so, but memory never went beyond 21MB. So I'm happy this is resolved.


var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });

function preload() {

    game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);

}

var sprites;
var rip = 0;

function create() {

    sprites = game.add.group();

    game.time.events.loop(50, createSprite, this);

}

function createSprite() {

    var mummy = sprites.create(0, game.world.randomY, 'mummy');

    mummy.animations.add('walk');

    mummy.play('walk', 10, true);

}

function update() {

    sprites.setAll('x', 10, true, true, 1);

    sprites.forEach(checkSprite, this, true);

}

function checkSprite(sprite) {

    try {
        if (sprite.x > game.width)
        {
            rip++;
            sprites.remove(sprite, true);
        }
    }
    catch (e)
    {
        console.log(sprite);
    }

}

function render() {

    game.debug.text("Group size: " + sprites.total, 32, 32);
    game.debug.text("Destroyed: " + rip, 32, 64);

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants