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

Particles are not being garbage collected after Emitter.destroy() #22

Closed
ben-zabloski opened this issue Mar 22, 2016 · 14 comments
Closed
Assignees

Comments

@ben-zabloski
Copy link

Calling particle.destroy nullifies particle.next causing the for loop to exit after destroying the first particle.

@andrewstart
Copy link
Contributor

So it does. That was pretty dumb on my part.

@ben-zabloski
Copy link
Author

No worries - programming happens!

I noticed when I was debugging a box2d particle I created - the box2d bodies weren't being cleaned up.

There may also be a few other memory issues too - Even after I modified the for loop to continue, particles seem to be sticking around when I check the heap snapshot profiler in chrome.

@andrewstart
Copy link
Contributor

When I get a chance to take care of this, I'll look around for other references.

@andrewstart
Copy link
Contributor

I released version 1.6.3, which fixes the emitter issue and does other cleanup improvements. I didn't see any other references within the library that would cause particles to stick around, though.

@ben-zabloski
Copy link
Author

Awesome - I'll check it out tomorrow - Thanks Andrew!

@adoxographer
Copy link

Hi,

I've been following this as well and have been trying to properly delete the particles but without success as well.

Having updated to 1.6.3 the problem still remains @andrewstart the issue is that it's being referenced by the renderer and never let go, unlike normal sprites

particleleak

I'm going to keep trying to figure it out but any help would be appreciated.

@andrewstart
Copy link
Contributor

Ah, I see - the SpriteRenderer is resetting the batch size in order to overwrite sprite batch entries which I assume has performance benefits from not trying to shrink and grow an array all the time. It also has the side effect of keeping references to destroyed sprites, if you have fewer sprites to draw than before. When you destroy a particle emitter, you suddenly have far fewer sprites than before. A workaround would be to reset the SpriteRenderer's sprites array when you want to wipe it, I believe with myWebGLRenderer.plugins.sprite.sprites.length = 0;.

@adoxographer
Copy link

@andrewstart unfortunately that doesn't seem to fix it, any ideas?

@andrewstart
Copy link
Contributor

That was my only easy idea. I'll have to dig into it this weekend.

@andrewstart andrewstart changed the title particle.destroy() loops only destroy the first particle. Particles are not being garbage collected after Emitter.destroy() Apr 8, 2016
@andrewstart andrewstart self-assigned this Apr 8, 2016
@andrewstart
Copy link
Contributor

The other reference keeping the particles from getting garbage collected has been fixed in 1.6.6. You'll still need to reset the SpriteRenderer's sprites array, but once you do that the particles should get properly taken care of.

@adoxographer
Copy link

@andrewstart that worked, I can confirm they're being properly disposed now.

Thanks!

@bigbadwofl
Copy link

bigbadwofl commented Jun 25, 2016

Upgraded to the latest pixi (4) and pixi particles (1.6.7) and particles are still not being destroyed properly.

Am I correct in assuming I can do:

emitter.emit = false;

and then a bit later

emitter.destroy();
this.renderer.plugins.sprite.sprites.length = 0;

When I step into the cleanup function, it doesn't find any particles to destroy (I wait until the particleCount == 0) even though I can still see a few faint dots on the screen.

@andrewstart
Copy link
Contributor

That should be correct. cleanup() removes any active particles, which shouldn't find any particles if you've waited for all the particles to expire. destroy() is what wipes the particle pool. Are you using a Container or ParticleContainer?

@bigbadwofl
Copy link

Thanks for getting back to me! I'm using a Container but I found my issue. I was removing the emitter from an array right after destroying it. Moving the array.splice to right before the emitter.destroy resolved my problem.

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

4 participants