box2d.js
box2d.js copied to clipboard
Memory leak
Hi,
I'm seeing an issue where I think world.DestroyBody does not completely clean everything up. I've created a jsfiddle here showing it: https://jsfiddle.net/otx84Lfb/12/
There is a debugging function in there that figures out how much memory is left on the heap. When creating b2BodyDef objects and destroying them, the available memory is exactly the same. After creating and destroying b2Body objects using the world.DestroyBody function, some memory is lost. In our application, this causes the emscripten heap to eventually fill up.
Is there something else I'm supposed to do when destroying a body? Thanks.
Two updates:
-
This also happens with version 2.3.1 (https://jsfiddle.net/otx84Lfb/13).
-
It appears to be due to the small block allocator. If I recompile after changing Allocate in b2BlockAllocator.cpp to just return b2Alloc(size), and Free in b2BlockAllocator.cpp to just return b2Free(p), then the memory leak goes away.
@timmyL17 perhaps you should report this to https://github.com/erincatto/Box2D.
I believe you are referencing this line: https://github.com/erincatto/Box2D/blob/master/Box2D/Box2D/Common/b2BlockAllocator.cpp#L106
Was this fixed?
I'm having the same issue... is there an update?
Tried this with box2d-wasm
(branch: memory-leak-repro
) against Box2D v2.4.1 sources, and I encounter the same memory leak:
mem start:
11411808
mem after body def destroy:
11411808
mem after destroy bodies__:
11395384
count:
0
items:
0
The library distribution against which I tested is here (only thing different compared to the npm release is I configured ALLOW_MEMORY_GROWTH=0
in order for the checkMemory
function in this repro to work correctly):
box2d-wasm-1.0.2.tar.gz