Iphone内存泄漏与malloc

时间:2010-04-14 16:12:17

标签: iphone memory-leaks malloc instruments

我有内存泄漏,由仪器发现它应该在这行代码中:

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

这实际上是教程中的代码片段,我认为这是无泄漏的  所以说。现在我估计,错误在其他地方,但我不知道,在哪里。

这是最后的引用:

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

有谁知道如何处理这个问题?

2 个答案:

答案 0 :(得分:1)

按照程序的逻辑,查看indices变量会发生什么。由于您为其分配了一些malloc存储空间,因此需要有相应的free

所以,弄清楚:

  • 该变量被释放的地方
  • 当那应该发生时
  • 有什么条件没有发生吗? (例如,由于错误而提前退出函数)

答案 1 :(得分:0)

可能还要仔细检查sizeof(indices [0])以确保它给出你期望的数字......