Objective-C 对象没有得到 dealloc:ed
我遇到了一个问题,对象未在 Objective-c 中释放。我很确定这是因为它被保留在某个地方,但我不知道在哪里(检查保留计数应该是 0 返回 1)。我已经多次检查我的代码,但没有看到哪些内容保留了我没有发布的内容。甚至可能是我正在使用的框架中的一个错误。
遇到这样的事情你会怎么处理?我想也许你可以搜索内存并查看指向该对象的内容,从而更容易找出它为什么是这样的,但我不太确定如何实现这一点。也许还有另一种解决方案?
I've got an issue with an object not being deallocated in objective-c. I'm pretty certain this is because it is being retained somewhere, but I don't know where (checking retainCount where it ought to be 0 returns a 1). I've gone through my code many times but fail to see what's retaining it that I don't release. Might even be a bug in the frameworks I'm using.
How would you deal with something like this? I thought maybe you could search through the memory and see what's pointing to this object, making it considerably easier to figure out why it is like this, but I'm not quite sure how to achieve that. Maybe another solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Instruments 很棒,并且可以检测到泄露的对象当它们被泄露时,但在这种情况下,我建议您首先使用 Xcode 静态分析器,是带有 Snow Leopard 的 Xcode 3.2 中的新增功能。 (如果您使用 Leopard,则可以使用命令行版本。)静态分析允许您甚至无需执行代码即可发现大量问题,并且在许多情况下比 Instruments 更容易使用。
Instruments is great, and can pick up on leaked objects if and when they are leaked, but in cases like these I suggest you first use the Xcode Static Analyzer, new in Xcode 3.2 with Snow Leopard. (If you're on Leopard, you can use the command-line version.) Static analysis allows you to find a great many problems without even executing your code, and in many cases is much easier to use than Instruments.
您是否尝试过工具?
Have you tried Instruments?
覆盖 -retain 和 -release,然后设置断点以查看谁在调用它们。
Override -retain and -release, then set breakpoints to see who's calling them.