Memory leak?

Discuss any Chipmunk bugs here.
Post Reply
__fastcall
Posts: 4
Joined: Thu May 29, 2008 8:12 pm
Contact:

Memory leak?

Post 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.
bennysce
Posts: 12
Joined: Sat Sep 27, 2008 3:14 am
Contact:

Re: Memory leak?

Post by bennysce »

just noticed this too running a memory leak checker.

i guess it's reported already then :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Memory leak?

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
zaldzbugz
Posts: 38
Joined: Tue Jan 19, 2010 2:45 am
Contact:

Re: Memory leak?

Post by zaldzbugz »

How do we release these memory leaks?

zaldzbugz
[color=#400000][i]"A man of tomorrow is forged by his battles today."[/i][/color]
User avatar
zaldzbugz
Posts: 38
Joined: Tue Jan 19, 2010 2:45 am
Contact:

Re: Memory leak?

Post by zaldzbugz »

can we just do this?

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

Zaldzbugz
[color=#400000][i]"A man of tomorrow is forged by his battles today."[/i][/color]
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Memory leak?

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
bluescrn
Posts: 5
Joined: Mon Aug 18, 2008 2:38 am
Contact:

Re: Memory leak?

Post 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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Memory leak?

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests