Memory leaks in btDefaultCollisionConfiguration ? [solved]

Post Reply
User avatar
tasora
Posts: 26
Joined: Mon Aug 15, 2005 8:57 am
Location: Italy
Contact:

Memory leaks in btDefaultCollisionConfiguration ? [solved]

Post by tasora »

Hallo Erwin,

I noticed that in Bullet examples (except in the Gimpact demo) the
btDefaultCollisionConfiguration object is never deleted.
In my code, I delete it by doing:

Code: Select all

bt_collision_configuration = new btDefaultCollisionConfiguration()
bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);  
bt_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax, max_objects);
bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);
  [.... do some collision detection....]
if(bt_collision_world) delete bt_collision_world;
if(bt_broadphase) delete bt_broadphase;
if(bt_dispatcher) delete bt_dispatcher; 
if(bt_collision_configuration) delete bt_collision_configuration;  // ***THE MISSING PART IN DEMOS??**
Well, the problem is that memory is not released (it allocates about 40Mb but it does NOT
free it! I had to modify the btDefaultCollisionConfiguration creator and destructor, so that
it deletes correctly the embedded pool allocators, but I fear that I 'broke' some optimization
(I see that aligned allocations were used..). I simply modified lines like the following

Code: Select all

void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
m_persistentManifoldPool = new (mem) btPoolAllocator(
   sizeof btPersistentManifold),DEFAULT_MAX_OVERLAPPING_PAIRS);
..into my modified code:

Code: Select all

m_persistentManifoldPool = new btPoolAllocator(
   sizeof(btPersistentManifold),DEFAULT_MAX_OVERLAPPING_PAIRS); 
(Of course also the deletion is modified, from btAlignedFree(m_collisionAlgorithmPool);
to the obvious delete m_collisionAlgorithmPool.)

I don't know if I missed something, or is it simply a 'work in progress' class
which still needed some finishing...

Alessandro Tasora
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Memory leaks in btDefaultCollisionConfiguration ?

Post by Erwin Coumans »

I noticed that in Bullet examples (except in the Gimpact demo) the btDefaultCollisionConfiguration object is never deleted.
Cleaning up the demos is work in progress, as mentioned in the Bullet 2.64 release note but the BasicDemo and all demos in AllBulletDemos should be fine. Have you checked Bullet 2.65 beta2?
Well, the problem is that memory is not released (it allocates about 40Mb but it does NOT free it! I had to modify the btDefaultCollisionConfiguration creator and destructor [...]
I just double checked this, and all memory is properly freed. You shouldn't need to make any code change. The destructor of btDefaultCollisionConfiguration does free the memory:

Code: Select all

btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
{
[...]

if (m_ownsPersistentManifoldPool)
	{
		m_persistentManifoldPool->~btPoolAllocator();
		btAlignedFree(m_persistentManifoldPool);
	}
[...]
}
Thanks,
Erwin
User avatar
tasora
Posts: 26
Joined: Mon Aug 15, 2005 8:57 am
Location: Italy
Contact:

Re: Memory leaks in btDefaultCollisionConfiguration ?

Post by tasora »

hallo,
Have you checked Bullet 2.65 beta2?
Mhh.. I am using bullet-2.64-rc2 ...
I just double checked this, and all memory is properly freed. You shouldn't need to make any code change. The destructor of btDefaultCollisionConfiguration does free the memory:
Ok, so maybe it's my fault.. I must check better.
The memory leakage was initially reported by one of the users of my library, where my 'physical system'
object creates a collision world in the following way:

Code: Select all

bt_collision_configuration = new btDefaultCollisionConfiguration()
bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);  
bt_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax, max_objects);
bt_collision_world = new btCollisionWorld(bt_dispatcher, bt_broadphase, bt_collision_configuration);
.... and later, at destruction, it frees these Bullet structures by doing:

Code: Select all

if(bt_collision_world) delete bt_collision_world;
if(bt_broadphase) delete bt_broadphase;
if(bt_dispatcher) delete bt_dispatcher; 
if(bt_collision_configuration) delete bt_collision_configuration;
Then, I made a simple test: I create/deleted few times my physical system object,
and I noticed that each time there were about 40MB left - and this leakage was
inherent to the bt_collision_configuration object above.
However I did not investigate too much in detail, because I supposed that the
btDefaultCollisionConfiguration class was still a work-in-progress (I thought this
because of the fact that I told you, i.e. that no demo used to delete it, so I
supposed that its implementation was still incomplete - here came my wrong
guess.. sorry!)

This weekend I will look better at this issue..

thank you!

Alessandro
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Memory leaks in btDefaultCollisionConfiguration ?

Post by Erwin Coumans »

Can you please upgrade to Bullet 2.65, and see if the problem is still there?

I've done extensive memory leak testing yesterday, and didn't find the leak.
Thanks a lot,
Erwin
User avatar
tasora
Posts: 26
Joined: Mon Aug 15, 2005 8:57 am
Location: Italy
Contact:

Re: Memory leaks in btDefaultCollisionConfiguration ?

Post by tasora »

Hallo Erwin,
Can you please upgrade to Bullet 2.65, and see if the problem is still there?
Ok, in fact I upgraded to the latest release of the Bullet SDK, and the problem
with memory leaks is fixed. Perfect!

Alessandro Tasora
Post Reply