如何确定哪些对象持有对其他对象的引用,这些对象会导致objective-c中的内存泄漏? [英] How can I determine which objects hold references to other objects that are causing memory leaks in objective-c?

查看:188
本文介绍了如何确定哪些对象持有对其他对象的引用,这些对象会导致objective-c中的内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用泄漏工具,并分析等找到泄漏,但它找不到它。使用分配我可以确定没有被释放的对象。

I have tried using the leaks tool, and "analyze" etc to find the leak, but it can't find it. Using allocations I can determine the objects which are not being released.

我注意到(通过在dealloc方法中添加调试语句),不会为这些对象调用dealloc。

I have noticed (by adding debugging statements in the dealloc method), that dealloc is not called for these objects.

如何确定哪些对象持有对这些对象的引用并阻止它们被释放?

How can I determine which objects are holding references to these objects and preventing them from being released?

推荐答案

无法检测到该问题。使用分配工具来捕获所有的引用计数是一个开始,但有很多类,我没有认识,或直接访问,我不能跟踪问题使用这种方法。相反,我列出了我直接负责的类,并逐行调查它们,直到我发现问题。原因是,我使用一些第三方库,没有减少我的一些对象的保留计数,如预期。我想在这种情况下,遵循更好的软件工程原理/设计模式,并有彻底的代码审查可能早就抓住了这个问题。

The analyze tool was unable to detect the problem. Using the allocations tool to capture all the reference counts was a start, but there were so many classes I didn't recognize, or access directly, I was not able to track down the problem using this method. Instead, I made a list of the classes that I was directly responsible for, and investigated each of them line by line till I found the problems. The cause was that I used some third party libraries which didn't decrement the retain count of some of my objects as expected. I guess in this case, following better software engineering principles / design patterns, and having thorough code reviews may have caught the problem earlier.

这篇关于如何确定哪些对象持有对其他对象的引用,这些对象会导致objective-c中的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆