0

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

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

有谁知道如何解决这个问题?

4

2 回答 2

1

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

所以,弄清楚:

  • 该变量在哪里被释放
  • 当这应该发生时
  • 有什么条件不发生吗?(例如,由于错误而提前退出函数)
于 2010-04-14T16:16:14.517 回答
0

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

于 2010-04-14T16:21:47.470 回答