Page 1 of 1

cpSpaceAddPostStepCallback - memory leak?

PostPosted: Mon Aug 23, 2010 7:38 am
by Peter
I've found that calling cpSpaceAddPostStepCallback consumes memory that seems to be never released, even on cpSpaceFree.

For example, in ChipmunkDemo:
Task Manager shows that at LogoSmash it uses ~8600Kb. After switching to Sensors(which uses PostStep callbacks) and waiting about 10 minutes, you'll notice that program uses much more memory. Back to LogoSmash - it is ~31000Kb instead of ~8600Kb.

So, 21 Mb of memory in 10 minutes - is this a bug or am I missing something?

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Mon Aug 23, 2010 8:48 am
by slembcke
Confirmed. That's kind of a nasty one too. I was forgetting to free a hash set that got allocated each frame a post step callback was used.

Good catch. I usually check the demo app for memory leaks before releasing, but I guess I missed that one.

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Fri Sep 10, 2010 3:04 pm
by paule
How do I fix this? It eats up my memory since I need to call it constantly. :(

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Fri Sep 10, 2010 3:50 pm
by slembcke
This bug has been fixed in trunk, but it looks like it hasn't made it out into a release yet.

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Sat Sep 11, 2010 3:27 am
by paule
Thanks for the information and the fixing :)

Will use the trunk until the release comes out. ;)

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Tue Sep 14, 2010 2:13 pm
by mlmcgoogan
Just ran into the leak myself. Thanks for the fix!

Keep up the awesome work!

Re: cpSpaceAddPostStepCallback - memory leak?

PostPosted: Tue Sep 14, 2010 3:28 pm
by slembcke
So I think this leak may have existed since I implemented the post-step callback feature... Not sure how it went so long without being noticed.