iPhone 内存泄漏与 malloc

发布于 2024-08-29 09:02:47 字数 763 浏览 5 评论 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

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2024-09-05 09:02:47

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

所以,弄清楚:

  • 该变量在哪里被释放
  • 当这种情况应该发生时,
  • ?当它不发生时是否有任何条件? (例如,由于错误而提前退出函数)

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)
橙幽之幻 2024-09-05 09:02:47

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文