How to manage memory and prevent leaks in JoltPhysics.js
mainBecause this is a WASM port, memory management is manual. JavaScript's garbage collector does not clean up WASM-allocated memory.
Manual Destruction
Every object created with new Jolt.XXX must be explicitly destroyed using Jolt.destroy(object).
Special Case: The Body class must be destroyed via the BodyInterface:
BodyInterface.DestroyBody(body.GetID()).
Reference Counting
Many classes inherit from RefTarget and use reference counting. If you want to maintain ownership, call object.AddRef(). To release ownership, call object.Release(). When the count reaches 0, the object is destroyed.
Common reference-counted classes include:
ShapeSettings,ShapeConstraintSettings,ConstraintPhysicsMaterialPhysicsSceneRagdoll,RagdollSettingsCharacterBase,CharacterBaseSettingsSkeleton,SkeletonAnimation,SkeletonMapperSoftBodySharedSettingsVehicleCollisionTester,VehicleControllerSettings,WheelSettings
Note: If you pass a reference-counted object to another Jolt object (e.g., passing ShapeSettings to CompoundShapeSettings), the receiving object automatically increments the reference count. In these cases, you do not need to call AddRef() yourself.