kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.32k stars 196 forks source link

Memory Leak ! release world in nodejs #80

Open shadow0162 opened 8 years ago

shadow0162 commented 8 years ago

I made an online game by using box2d.js on server side. one vs battle is a new box2d world. While battle end, I release b2d world by destory.

b2d.destroy(this.world);

But the memory still increase by 40M(almost 150+ b2body). what the best way to release the memory of box2d world and all bodies?

kripken commented 8 years ago

The guaranteed way is to put box2d.js itself and your code inside a function. Then when that function exits, only things you keep holding on to are reachable by the JS engine, and it will eventually GC all the rest.

shadow0162 commented 8 years ago

thanks, I will try it