How can I determine which objects hold references to other objects that are causing memory leaks in objective-c?(如何确定哪些对象持有对导致 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 内存泄漏的其他对象的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何确定哪些对象持有对导致 Objective-c 内存泄漏的其他对象的引用?
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01