0

I found a memory leak in my code, but i can not figure out how to fix it.

When i loop like this:

for (;;)
{
    physx::PxMaterial *pMaterial = pPhysic_physicsSDK->createMaterial(0.5f, 0.5f, 0.5f);
    pMaterial->release();
}

I have memory overflow. Memory are not releasing. How to release it right?

I tried to delete it "delete pMaterial", but no delete access is granted.

Stas BZ
  • 1,184
  • 1
  • 17
  • 36

1 Answers1

0

You're never breaking from the for loop. It will never stop running unless you call break;.

for (;;)
{
    physx::PxMaterial *pMaterial = pPhysic_physicsSDK->createMaterial(0.5f, 0.5f, 0.5f);
    pMaterial->release();

    if(**something is satisfied**)
        break;
}

This would stop the memory overflow because it will eventually leave the for loop.

Darrell
  • 638
  • 4
  • 17
  • I know it. But in my code above. I suggest it have not to eat all my memory, because i release it in every loop. But it does! – Stas BZ Aug 28 '14 at 13:19
  • Did you try dereferencing the pointer using "&" when calling delete, instead of release – Darrell Aug 28 '14 at 13:23
  • try printing what pMaterial contains after you release it to make sure it is actually being released... see if that helps – Darrell Aug 28 '14 at 13:35