-
Notifications
You must be signed in to change notification settings - Fork 195
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 in repeated b2Body.GetLinearVelocity calls #83
Comments
I assume you meant it returns a value, not a reference? Returning a value is ok - our glue code does this:
So it doesn't allocate a new object each time (but the objects are just valid until the next call). When you say the memory footprint expands, how are you measuring it? |
Honestly, the most obvious is that seconds of interaction cause Box2D to crash, complaining about running out of memory. Commenting out the single (repeated) |
What complains? Browser, app, or OS? What is the message? |
In the browser console:
|
I see. Surprising, I have no idea what could cause that. Can you perhaps make a small testcase that shows the issue deterministically? |
I don't appear to be easily able to reproduce. Perhaps it would be helpful to explain the full situation. We have a body that we drag around with world, colliding with a dense field of other bodies. It's pretty slow (due to there being so many bodies), so I was hoping to be able to improve performance by sleeping bodies that are moving at velocities below a certain threshold. To do this, I'm iterating through all the bodies, checking their velocity, and if it's below the threshold, calling |
No idea, sorry. But it must be somehow connected to the other operations around it, as I don't see how GetLinearVelocity by itself could cause that. Or, perhaps it's not related to the wrapper code at all - maybe this is a bug in box2d in native builds as well, i.e., maybe GetLinearVelocity allocates something that isn't freed. |
That seems the most likely explanation to me, but I can't see any obvious alarm bells (though I am not a C programmer). |
I'm finding that when calling
b2Body.GetLinearVelocity
in a loop, the memory footprint expands. We have ~2000 bodies (a lot I know), and callGetLinearVelocity
on each of them once every frame, andBox2D
runs out of memory very quickly (in seconds).I have tried caching the return value of the
GetLinearVelocity
, but it doesn't seem to be updating theLengthSquared
unless I make another call toGetLinearVelocity
(even if the result of that call is discarded).Is this possibly related to the fact that
GetLinearVelocity
returns a reference?The text was updated successfully, but these errors were encountered: