iPhone 内存泄漏与 malloc
我有内存泄漏,由仪器发现,它应该在这行代码中:
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
有人知道如何解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遵循程序的逻辑,查看
indices
变量发生了什么。由于您为其分配了一些malloc
存储空间,因此需要有一个相应的free
。所以,弄清楚:
Follow the logic of your program, looking at what happens to the
indices
variable. Since you assigned somemalloc
storage to it, there needs to be a correspondingfree
.So, figure out:
可能还想仔细检查 sizeof(indices[0]) 以确保它给出您期望的数字......
Might want to also double check sizeof(indices[0]) to make sure its giving the number you expect...