Memory Leak with Physics Elements

Hi…I’m working on a research project where I’m spawning bodies (like the ragdoll in that demo) in successive iterations. I’m spawning a new body and attempting to dispose of the old one, and I’m experiencing a memory leak (the frame rate is slowing with each successive iteration).

So per the ragdoll demo, I have a node for the body to which I’m attaching multiple CapsuleCollisionShape and RigidBodyControl, as well as Geometry for visualization. The nodes for each limb are joined with a SixDofJoint as well. Simply removing the primary body node doesn’t help, and I’ve also tried manually removing each individual element from the scene graph and physics space. So far the slowdown continues. I also installed the profiling plugin, but the results have not been helpful in identifying the issue.

Alternatively, I wouldn’t mind just repositioning the body in its original starting point, but “teleporting” all the elements with physics included seems to be more complicated than expected, and I found an old forum post where it was not recommended.

Thanks in advance for any help.

As you’ve noticed, the scene graph and physics space are separate, and must be cleaned up separately. When disposing of physics elements, they must be removed in the same “way” you added them, for instance don’t use physicsSpace.removeAll (spatial), when you didn’t use an physicsSpace.addAll (spatial) to begin with. I’ve not really used the Physics Ragdoll, so I don’t know if theres anything special you need to do with that.