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

How to know if an object needs Ammo.destroy()? #355

Open
jespertheend opened this issue Feb 5, 2021 · 2 comments
Open

How to know if an object needs Ammo.destroy()? #355

jespertheend opened this issue Feb 5, 2021 · 2 comments

Comments

@jespertheend
Copy link

I'm calling new Ammo... quite often. What classes should be destroyed and when?
If I pass a new vector to btRigidBody.setAngularFactor() for instance, should I Ammo.destroy(vec) right after that? Or should I wait for the rigidbody to be destroyed as well? Or do vectors not need to be destroyed?

Or what about Ammo.btRigidBodyConstructionInfo for instance? How can I know if and when to destroy an object?

@LeXXik
Copy link
Contributor

LeXXik commented May 9, 2021

If you create something with a keyword new, you should destroy it when no longer needed. When you set a property, for example a velocity, from a vector, the values get copied and you no longer need that vector afterwards. Vectors are a good candidates for re-use, however. For example, instead of creating a new Ammo vector on each transform update, you can create it once and re-use it by updating its components to update the bodies in the physics world. A collision shape could be a good candidate for destruction after the body is added to the world. Basically, if you no longer need an Ammo object and have no plans on using it in the near future - destroy it. Same with btRigidBodyConstructionInfo - destroy after the body is created.

@jespertheend
Copy link
Author

Ah thanks for the info! From what I remember I used destroy() for basically every new object. But I was still getting out of memory crashes and I couldn't seem to fix it. I ended up moving to my own physics engine in the end, since we were only using a few features.

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

2 participants