Memory leak (b2Vec2) in Box2d 2.1a - sample project - Help

Discuss issues specific to the Flash/AS3 port of Box2D
pinfred
Posts: 7
Joined: Tue Feb 22, 2011 11:53 am

Memory leak (b2Vec2) in Box2d 2.1a - sample project - Help

Postby pinfred » Wed Feb 23, 2011 1:39 am

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!
Attachments
testBox2D.rar
Project sample to reproduce Memory leak
(214.79 KiB) Downloaded 563 times

pinfred
Posts: 7
Joined: Tue Feb 22, 2011 11:53 am

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby pinfred » Fri Feb 25, 2011 1:04 am

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
Attachments
testBox2D.rar
Box2D memory leak
(214.9 KiB) Downloaded 413 times

pinfred
Posts: 7
Joined: Tue Feb 22, 2011 11:53 am

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby pinfred » Fri Feb 25, 2011 1:47 am

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.
Attachments
memoryleak2.1a.jpg
memoryleak2.1a.jpg (87.6 KiB) Viewed 8685 times

Tapir
Posts: 28
Joined: Sat Jul 26, 2008 5:04 pm

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby Tapir » Sun Feb 27, 2011 7:07 pm

have you ever tried fbox2d? viewtopic.php?f=8&t=5924

pinfred
Posts: 7
Joined: Tue Feb 22, 2011 11:53 am

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby pinfred » Mon Feb 28, 2011 6:15 am

No, I didn't know.
I will look
Thanks!

pinfred
Posts: 7
Joined: Tue Feb 22, 2011 11:53 am

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby pinfred » Mon Feb 28, 2011 6:22 am

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
Attachments
memoryleakFix2.1a.jpg
memoryleakFix2.1a.jpg (82.93 KiB) Viewed 8653 times

ViZgl
Posts: 4
Joined: Wed Aug 18, 2010 6:35 am
Contact:

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby ViZgl » Sat Dec 24, 2011 3:19 pm

It still does not work

Penry
Posts: 6
Joined: Sun Jan 08, 2012 10:07 am

Re: Memory leak (b2Vec2) in Box2d 2.1a - sample project - He

Postby Penry » Sun Jan 08, 2012 11:11 am

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)


nazar83
Posts: 7
Joined: Fri Apr 03, 2015 9:37 am
Location: Nigni Novgorod

Memory leak b2Vec2 in Box2d 2 1a sample project Help

Postby nazar83 » Sat Apr 18, 2015 3:19 am

I am sorry, that has interfered... This situation is familiar To me. I invite to discussion. Write here or in PM.


Return to “Flash”



Who is online

Users browsing this forum: Baidu [Spider] and 1 guest