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

Memory leak when tween assigned #1063

Open
DarkMatters opened this issue Apr 2, 2021 · 1 comment
Open

Memory leak when tween assigned #1063

DarkMatters opened this issue Apr 2, 2021 · 1 comment

Comments

@DarkMatters
Copy link

I discovered a memory leak when removing children that have a tween on them.

in my case, a child has a tween looping forever. when the parent is destructed, the tween is never freed.

   var sprite= new new createjs.Sprite(sheet, frame);
   var child = new createjs.Shape(graphics);
   createjs.Tween.get(child, { loop: -1 })
                .to({ alpha: 0 }, 1000, createjs.Ease.getElasticIn(2, 5))
                .to({ alpha: 0.5 }, 1000, createjs.Ease.getElasticIn(2, 5));

then when I'm done with the sprite:

   sprite.removeAllChildren();
   stage.removeChild(sprite);

this causes a memory leak. while the solution isn't hard, you can manage resources yourself

   var child = sprite.getChildAt(index);
   createjs.Tween.removeTweens(child);
   sprite.removeAllChildren();
   stage.removeChild(sprite);

it really seems to be a good library it should somehow do this internally, as the library is good about cleaning everything else up, and there doesn't seem to be any documentation anywhere that you need to call remove tweens when tween loop forever or if you destruct their targets before the tween completes.

I wanted to run this by everyone to see what the thoughts are on this before I started to look into it further.

@danzen
Copy link
Contributor

danzen commented Apr 2, 2021

Hi @DarkMatters - thanks for the report. I wonder if we would want the animation to still be going if we add the child back. When we dispose() in ZIM we recursively go through children and remove animations. But when we remove the child, we do not stop the animations. I do not think there is a dispose in CreateJS so perhaps it is up to the developer to manually remove tweens if they are not going to use them again. I agree, that is tricky to remember and probably does seem like it would be a given. It could be added to the docs at least as an interim solution. Anyone else have any thoughts? Cheers.

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

No branches or pull requests

2 participants