Page 1 of 1
Memory Leak from Linking
Posted: Sat Dec 03, 2011 8:42 pm
by Geometrian
Hi,
There appears to be a small memory leak, apparently caused merely by linking. Adding either of the following (they are NEVER run):
Code: Select all
solver = new btSequentialImpulseConstraintSolver();
. . . or
Code: Select all
dynamics = new ::btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collision_configuration);
dynamics->setGravity(btVector3(0,-10,0));
. . . will produce the following CRT output on Windows:
Code: Select all
Detected memory leaks!
Dumping objects ->
{144} normal block at 0x00625088, 32 bytes long.
Data: < # x 5# > 0E AA 23 00 00 00 00 00 78 CA 35 23 CD CD CD CD
Object dump complete.
Ideas? Thanks,
Ian
Re: Memory Leak from Linking
Posted: Thu Dec 22, 2011 9:43 pm
by DannyChapman
I'm getting this too with 2.79. If I do:
Code: Select all
mGliderGame->mCollisionConfiguration = new btDefaultCollisionConfiguration();
mGliderGame->mDispatcher = new btCollisionDispatcher(mGliderGame->mCollisionConfiguration);
mGliderGame->mOverlappingPairCache = new btDbvtBroadphase();
mGliderGame->mSolver = new btSequentialImpulseConstraintSolver;
mGliderGame->mDynamicsWorld = new btDiscreteDynamicsWorld(
mGliderGame->mDispatcher,
mGliderGame->mOverlappingPairCache,
mGliderGame->mSolver,
mGliderGame->mCollisionConfiguration);
then
Code: Select all
mDynamicsWorld->stepSimulation(1.f/60.f,10);
then clear up
Code: Select all
// terminate physics
delete mGliderGame->mDynamicsWorld;
delete mGliderGame->mSolver;
delete mGliderGame->mOverlappingPairCache;
delete mGliderGame->mDispatcher;
delete mGliderGame->mCollisionConfiguration;
the memory leak checker (I'm using Marmalade) reports a leak. If I miss out the call to stepSimulation then there's no leak reported.
This is without any other Bullet code at all (i.e. no objects yet - though it happens if I create them too).
Digging into it now, but any pointers would be appreciated.
Re: Memory Leak from Linking
Posted: Thu Dec 22, 2011 9:46 pm
by DannyChapman
10 seconds later (well, perhaps 20):
Some hunch made me turn off profiling (#define BT_NO_PROFILE 1 in btQuickprof.h) and that got read of this leak.
Re: Memory Leak from Linking
Posted: Sun Feb 05, 2012 7:02 am
by Geometrian
Hmmm . . . still getting the leak.
Re: Memory Leak from Linking
Posted: Sun Feb 05, 2012 11:56 am
by Ripiz
Geometrian, can you post your initialization and destruction?
Code posted by DannyChapman doesn't have any leaks:
Code: Select all
btDefaultCollisionConfiguration *mCollisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher *mDispatcher = new btCollisionDispatcher(mCollisionConfiguration);
btDbvtBroadphase *mOverlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver *mSolver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld *mDynamicsWorld = new btDiscreteDynamicsWorld(
mDispatcher,
mOverlappingPairCache,
mSolver,
mCollisionConfiguration
);
mDynamicsWorld->stepSimulation(1.f/60.f,10);
delete mDynamicsWorld;
delete mSolver;
delete mOverlappingPairCache;
delete mDispatcher;
delete mCollisionConfiguration;
Re: Memory Leak from Linking
Posted: Sun Feb 05, 2012 3:56 pm
by Geometrian
There's some bullet code, but it is never ever run. The memory leak appears only when some functionality is linked.
Thanks,
Ian
Re: Memory Leak from Linking
Posted: Mon Feb 06, 2012 3:00 pm
by Ripiz
So memory leak appears after you add functionality, which is never executed?
In that case, are you sure you destroy all objects you created?
Code: Select all
physics->removeRigidBody(...);
delete RigidBody;
delete CollisionShape;
Are you sure it's not your code causing leak at all?
Re: Memory Leak from Linking
Posted: Tue Feb 14, 2012 12:58 am
by Erwin Coumans
Can you try to use the great free and open source
Visual Leak Detector in combination with Visual Studio? It will give you a full call stack where the leaked memory was allocated.
(make sure to statically link against Bullet, and use the DLL version of the C run-time)
It is very easy to use: just add an
anywhere in your code base, and link against the right library.
Thanks,
Erwin
Re: Memory Leak from Linking
Posted: Tue Feb 14, 2012 1:18 am
by Geometrian
When using VLD, no leaks are reported:
Code: Select all
Visual Leak Detector Version 2.2.2 installed.
...
No memory leaks detected.
Visual Leak Detector is now exiting.
CRT produces the output given above. Again:
Code: Select all
Detected memory leaks!
Dumping objects ->
{146} normal block at 0x028952E0, 32 bytes long.
Data: <_ 3 ( > 5F A8 33 00 00 00 00 00 C9 28 F0 00 CD CD CD CD
Object dump complete.
Thanks!
Re: Memory Leak from Linking
Posted: Sun Apr 07, 2013 7:09 pm
by Geometrian
Ripiz wrote:So memory leak appears after you add functionality, which is never executed?
In that case, are you sure you destroy all objects you created?
Code: Select all
physics->removeRigidBody(...);
delete RigidBody;
delete CollisionShape;
Are you sure it's not your code causing leak at all?
Exactly. The code that's causing the leak never runs. My suspicion then is that it's triggering the link inclusion of something in Bullet that's causing a memory leak. With no physics code whatsoever running, the leak still occurs. Commenting these lines out fixes the problem.
I did (re)try to #define BT_NO_PROFILE 1 in LinearMath/btQuickprof.h (line 19), but this time I also rebuilt the libraries. This seems to fix the problem.
Re: Memory Leak from Linking
Posted: Tue Nov 26, 2013 9:32 pm
by Geometrian
This still occurs in 2.82.
I'm fairly sure at least part of the problem is that the "static btClock gProfileClock;" declared at btQuickprof.cpp:21 allocates memory that is never freed.