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

查看:25
本文介绍了如何确定哪些对象持有对导致 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天全站免登陆