Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Memory Leak from Linking
PostPosted: Sat Dec 03, 2011 8:42 pm 
Offline

Joined: Sat Dec 03, 2011 8:37 pm
Posts: 15
Hi,

There appears to be a small memory leak, apparently caused merely by linking. Adding either of the following (they are NEVER run):
Code:
solver = new btSequentialImpulseConstraintSolver();
. . . or
Code:
dynamics = new ::btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collision_configuration);
dynamics->setGravity(btVector3(0,-10,0));
. . . will produce the following CRT output on Windows:
Code:
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


Top
 Profile  
 
PostPosted: Thu Dec 22, 2011 9:43 pm 
Offline

Joined: Sun Jan 07, 2007 4:29 pm
Posts: 44
Location: Oxford, England
I'm getting this too with 2.79. If I do:

Code:
  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:
  mDynamicsWorld->stepSimulation(1.f/60.f,10);


then clear up

Code:
  // 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.


Top
 Profile  
 
PostPosted: Thu Dec 22, 2011 9:46 pm 
Offline

Joined: Sun Jan 07, 2007 4:29 pm
Posts: 44
Location: Oxford, England
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.


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 7:02 am 
Offline

Joined: Sat Dec 03, 2011 8:37 pm
Posts: 15
Hmmm . . . still getting the leak.


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 11:56 am 
Offline

Joined: Mon Aug 16, 2010 10:43 am
Posts: 47
Geometrian, can you post your initialization and destruction?

Code posted by DannyChapman doesn't have any leaks:
Code:
   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;


Top
 Profile  
 
PostPosted: Sun Feb 05, 2012 3:56 pm 
Offline

Joined: Sat Dec 03, 2011 8:37 pm
Posts: 15
There's some bullet code, but it is never ever run. The memory leak appears only when some functionality is linked.
Thanks,
Ian


Top
 Profile  
 
PostPosted: Mon Feb 06, 2012 3:00 pm 
Offline

Joined: Mon Aug 16, 2010 10:43 am
Posts: 47
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:
physics->removeRigidBody(...);
delete RigidBody;
delete CollisionShape;


Are you sure it's not your code causing leak at all?


Top
 Profile  
 
PostPosted: Tue Feb 14, 2012 12:58 am 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
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
Code:
#include <vld.h>

anywhere in your code base, and link against the right library.

Thanks,
Erwin


Top
 Profile  
 
PostPosted: Tue Feb 14, 2012 1:18 am 
Offline

Joined: Sat Dec 03, 2011 8:37 pm
Posts: 15
When using VLD, no leaks are reported:
Code:
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:
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!


Top
 Profile  
 
PostPosted: Sun Apr 07, 2013 7:09 pm 
Offline

Joined: Sat Dec 03, 2011 8:37 pm
Posts: 15
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:
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group