# PhysX: createActor/releaseActor memory problems

## Recommended Posts

Tct    122
Hi, I have serious memory problems with PhysX and was wandering if someone could help me out. So here's what I am doing: 1. Create NxPhysXSDK 2. Create NxPhysXScene 3. Perform a loop with creating/releasing static object
int iterate = 10000;
for(int i=0;i<iterate ;i++)
{
NxBoxShapeDesc boxDesc;
boxDesc.dimensions = NxVec3((float)size, (float)size, (float)size);

NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&boxDesc);
actorDesc.globalPose.t  = pos;
NxActor* actor = gScene->createActor(actorDesc);
gScene->releaseActor(*actor);
}

As you can see, after creating an actor, I am releasing it, so logically thinking, I should have the same memory amount as before creating/releasing those actors, of course due to fragmentation, it may slightly increase.... But memory amount consumed is in megabytes, which firstly looked like a leak. After some investigation, I noticed that the similar code:
int iterate = 10000;
for(int i=0;i<iterate ;i++)
{
NxBoxShapeDesc boxDesc;
boxDesc.dimensions = NxVec3((float)size, (float)size, (float)size);

NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&boxDesc);
actorDesc.globalPose.t  = pos;
NxActor* actor = gScene->createActor(actorDesc);
gScene->releaseActor(*actor);
gScene->simulate(0.01f);
}

won't produce this so called 'leak', so this makes me think, that PhysX has some kind of pool inside, which is reseted after simulate is called. The thing is that I can't call simulate, because I am in so called edit mode, that means no physics should be performed. Another thing which you might ask why I am creating/releasing actors, it's because it's a static object, and it cannot be moved (according to PhysX documentation), so the only way to 'move it' is to recreate it. So in short, does anyone know how to reset that inner PhysXScene pool, so memory wouldn't be consumed so much? P.S gScene->simulate(0.0f), won't work Thx

##### Share on other sites
lXciD    122
I believe the reason behind the behavior is more because of PhysX deferred the deletion of actors events probably for simulation stability purposes but this is just my guess.

If you need to move the objects, I suggest making the object kinematics rather than static. Static are meant for object that doesn't move. You might want to represents them differently in your editor (kinematic) and your game (static).