planck.js icon indicating copy to clipboard operation
planck.js copied to clipboard

Processing & Memory

Open Cdvalencia opened this issue 4 years ago • 3 comments

Hi Shakiba.

i am using "planck-with-testbed.js". and each time that i need restart elements and clear my world, i execute destroyBody by all elements list

nextBody=world.getBodyList();
while (nextBody) {
  world.destroyBody(nextBody);
  nextBody=nextBody.getNext();
}

but the elements continuos consuming memory.

image

each time that restore elements, the memory to be duplicate and make my app each time more slow.

exists some way one function, that allow clear all elements in my world automatically.

Cdvalencia avatar May 13 '21 01:05 Cdvalencia

Thanks for reporting, I will check it out. Does it happen only with testbed, or do you see same issue with core library as well?

shakiba avatar May 13 '21 22:05 shakiba

i only have used the testbet.

Cdvalencia avatar May 14 '21 15:05 Cdvalencia

Be aware that destroyBody is ignored if invoked during a callback

bobcgausa avatar May 17 '21 15:05 bobcgausa

@shakiba this seems to be an issue with the core library as well. Users reported a fatal memory leaks in their bullet hell game. Did you find a solution?

Here's the code I use to remove sprites. Do I need to do something else?

if (this.body) this.p.world.destroyBody(this.body);
this.removed = true;

// when removed from the "scene" also remove all the references in all the groups
while (this.groups.length > 0) {
	this.groups[0].remove(this);
}

quinton-ashley avatar Dec 13 '22 10:12 quinton-ashley

@quinton-ashley It seems you discussed it here and you were able to resolve the issue in your case? Were you able to confirm that there was not memory leak when removing bodies, or should I try to reproduce this?

shakiba avatar Aug 23 '23 05:08 shakiba

Yup all good it was resolved

quinton-ashley avatar Aug 23 '23 06:08 quinton-ashley

@Cdvalencia It seems it works fine for Quinton, so I'm closing this. But please feel free to open if needed, and it would be helpful if you could provide an example (without any other library) to reproduce it.

shakiba avatar Aug 23 '23 07:08 shakiba