Page 1 of 1

Memory leak?

Posted: Mon Jul 07, 2008 2:14 am
by __fastcall

Code: Select all

// cpcollision.c @ 349 :
colfuncs = (collisionFunc *)calloc(CP_NUM_SHAPES*CP_NUM_SHAPES, sizeof(collisionFunc));
From what I could find, colfuncs doesn't seem to be freed anywhere... Of course, this isn't a serious bug; not that much memory is lost and it eventually gets returned to the system anyways.

Re: Memory leak?

Posted: Fri Jul 10, 2009 4:58 pm
by bennysce
just noticed this too running a memory leak checker.

i guess it's reported already then :)

Re: Memory leak?

Posted: Sat Jul 11, 2009 12:22 pm
by slembcke
I guess I didn't really consider this a memory leak as you will probably be using Chipmunk until the program exits, and it's only a few bytes of RAM anyway.

Re: Memory leak?

Posted: Wed Jul 21, 2010 11:14 pm
by zaldzbugz
How do we release these memory leaks?

zaldzbugz

Re: Memory leak?

Posted: Thu Jul 22, 2010 12:09 am
by zaldzbugz
can we just do this?

int *ntable = (int *) calloc (nn,sizeof(int));
free (ntable);

Zaldzbugz

Re: Memory leak?

Posted: Thu Jul 22, 2010 10:45 am
by slembcke
Yes, for any memory that you malloc(), calloc(), or realloc() you must call free() on it at some point. The memory is freed automatically by the OS when your application exits as well.

Re: Memory leak?

Posted: Mon Mar 14, 2011 2:04 pm
by bluescrn
slembcke wrote:I guess I didn't really consider this a memory leak as you will probably be using Chipmunk until the program exits, and it's only a few bytes of RAM anyway.
It's definitely a memory leak though - if you use your own memory manager ( malloc/free replacements ) with any sort of leak detection, it shows up after adding your very first Chipmunk function call... If I'd never touched the library before, that would be quite offputting - but I've messed with it on PC, so I know how cool it is :)

I'm just having a go at using Chipmunk with the Airplay SDK (http://www.airplaysdk.com) - and that fires a big ugly assert if you haven't freed all your mallocs when your app exits (at least it does on the x86 build). I've added a little 'cpReleaseChipmunk()' locally to fix it - but looking at it again, it doesn't really need allocating dynamically at all, does it - it's a tiny little fixed-size array?

Re: Memory leak?

Posted: Mon Mar 14, 2011 3:15 pm
by slembcke
Retaining memory that you are using until program exit is not a leak. The OS must clean up after every process exits anyway. It's not lazy to let the OS do it. Going out of your way to deallocate every last bit of RAM on exit serves no purpose except to increase the changes of introducing errors. Cocoa does not free all memory when it exits (on purpose), most garbage collected languages don't free memory on exit (on purpose). Worrying about a single 36 byte allocation is a bit odd to me when a platform powerful enough to make Chipmunk useful will have at least a few megabytes of RAM. It's not really like you need the space back when Chipmunk isn't simulating anything.

Also, you're right that it doesn't really need to be allocated anymore, but I've never gone back to change it. I just didn't want to spend the time to populate the table by hand. It seems pretty unimportant in the grand scheme of things.