Memory management rules?

SatelliteBiker
Posts: 7
Joined: Wed Jan 20, 2010 2:30 pm

Memory management rules?

Post by SatelliteBiker »

I'm new to the Bullet library and am porting a simple sim I have to Bullet.

Is there documentation that describes memory management/object ownership policy?

Like some of the demos, my code stores the collision shapes for deletion later.
But what about some of the other objects, such as btMotionStates instantiated and passed to RigidBodyConstructionInfo objects? Should I be deleting the MotionStates after creating a new rigid body, or does RigidBodyConstructionInfo delete it? Can I reuse MotionStates for other rigid body creation?

Are there any tricky cases with Bullet?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Memory management rules?

Post by Erwin Coumans »

Memory management rules are simple: the one who allocates memory is responsible for deletion.

For collision shapes, that can be shared among several objects, it is best to keep a separate array and delete them at the end.

Also, the order of deletion is reversed of creation. See Bullet/HelloWorld for an example how to allocate and delete objects.
Thanks,
Erwin
SatelliteBiker
Posts: 7
Joined: Wed Jan 20, 2010 2:30 pm

Re: Memory management rules?

Post by SatelliteBiker »

Yep, that's simple enough.

And I now fully understand the object deletion code at the end of hello world. Instantiating the MotionState and RigidBody objects earlier and saving them into locally-scoped variables initially looked like leaks to me.

Thanks Erwin.