views:

257

answers:

2

Hello.

I have memory leak, found by instruments and it is supposed to be in this line of code:

indices = malloc( sizeof(indices[0]) * totalQuads * 6);

This is actually a code snippet from a tutorial, something which i think is leak-free so to say. Now I reckon, the error is somewhere else, but I do not know, where.

These are the last trackbacks:

5 ColorRun -[EAGLView initWithCoder:] /Users/me/programming/colorrun_3.26/Classes/EAGLView.m:98
4 ColorRun -[EAGLView initGame] /Users/me/programming/colorrun_3.26/Classes/EAGLView.m:201
3 ColorRun -[SpriteSheet initWithImageNamed:spriteWidth:spriteHeight:spacing:imageScale:] /Users/me/programming/colorrun_3.26/SpriteSheet.m:68
2 ColorRun -[Image initWithImage:scale:] /Users/me/programming/colorrun_3.26/Image.m:122
1 ColorRun -[Image initImpl] /Users/me/programming/colorrun_3.26/Image.m:158
0 libSystem.B.dylib malloc

Does anyone know how to approach this?

+1  A: 

Follow the logic of your program, looking at what happens to the indices variable. Since you assigned some malloc storage to it, there needs to be a corresponding free.

So, figure out:

  • where that variable gets freed
  • when that's supposed to happen
  • are there any conditions when it doesn't happen? (for example, exiting a function early due to an error)
David Gelhar
A: 

Might want to also double check sizeof(indices[0]) to make sure its giving the number you expect...

evilertoaster