Hello,
I think there is a memory leak when create/destroy many bodies.
I have done a sample test project in flex 3 with this post.
When I use profiler, b2Vec2 instances grow more and more.
To use de sample project, just clic the flash to gain focus and press space bar to create bodies.
Created bodies will destroy themself 3s later.
You will need to monitor b2Vec2 (as I said I used flex3 profiler)
I also try with the trunk version. Same results (moreover, there is a sleeping bodies issu, they don't want to sleep)
Any help to fix this memory leak ?
Thanks!
Hi,
No help on this ?
I have more investigate.
I add trace the number of B2Body.
When you press space bar bodies are created. As you can see the trace #bodies come back to 1 (seems to have always a minimum one one body at the creation of the world) after destroying them. Nice from it. BUT if you look at the profiler you will see that only ~half of the instances of b2Body are destroyed ! I think that it could explain also why b2Vec2 are also in memory.
So now the question is : why ~half of the instance of the b2Body remains in memory and are not destroyed (even after garbage memory) ?
Feel free to use the attached project I made
Fred
Hi again,
I have made a "unit test" that create 2033 bodies (see cumulatices instances) and destroy them.
So what we could learn (see attached picture) ?
There is a problem on freeing b2Vect2 (11787 instances in memory with represent 64% of total memory !), b2Sweep (1395 instance on memory), b2Mat22, b2MatTransform b2Body. There are the biggest memory leak.
The other (b2AABB, b2dynamicTreenode, etc... are small leak)
I have find a fix for some (I will post ). The problem is that in AS3 memory is not garbaged collected if there is some references with are not set to null.
No, I didn't know.
I will look
Thanks!
Here is the main fix for the memory leak (see by yourself result memory attached and compare with the previous)
There are other similar fix to do...
Line 1238 of b2Body.as
// Destructor
//~b2Body();
public function Destroy():void {
m_userData = null;
m_sweep = null;
m_xf = null;
m_linearVelocity = null;
m_force = null;
m_world = null;
m_prev = null;
m_next = null;
m_fixtureList = null;
m_controllerList = null;
m_jointList = null;
m_contactList = null;
}
Call this on b2world.as function DestroyBody(b:b2Body)
--m_bodyCount;
b.Destroy();
//b->~b2Body();
//m_blockAllocator.Free(b, sizeof(b2Body));
Pinfred
I've just found a memory leak (will post in more detail seperatly) - it only appears to affects body's which are B2CircleShape - and only under ver specific conditions (it may be what you are experiencing too)
I am sorry, that has interfered... This situation is familiar To me. I invite to discussion. Write here or in PM.