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 #90

Open
timmyL17 opened this issue Jun 14, 2017 · 5 comments
Open

Memory leak #90

timmyL17 opened this issue Jun 14, 2017 · 5 comments

Comments

@timmyL17
Copy link

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.

@timmyL17
Copy link
Author

timmyL17 commented Jun 19, 2017

Two updates:

  1. This also happens with version 2.3.1 (https://jsfiddle.net/otx84Lfb/13).

  2. 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.

@calvinte
Copy link

calvinte commented Feb 4, 2018

@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

@soylomass
Copy link

Was this fixed?

@joex92
Copy link

joex92 commented Nov 3, 2020

I'm having the same issue... is there an update?

@joex92 joex92 mentioned this issue Nov 3, 2020
@Birch-san
Copy link

Birch-san commented Nov 4, 2020

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

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

5 participants