gpt4 book ai didi

objective-c - 如何检测 Objective-C 中的变量是否未被释放?

转载 作者:行者123 更新时间:2023-11-29 13:49:03 26 4
gpt4 key购买 nike

我已经从我的代码中删除了一些版本,以查看 xCode 中的 Leaks 工具是否可以通知我有关错误代码的信息:

...
UINavigationController *masterNav = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detail];
[master release];

splitViewController.viewControllers = [NSArray arrayWithObjects:masterNav, detailNav, nil];
//[masterNav release]; [detailNav release]; commented out

但是我看不到任何通知。是因为分配给这类变量的内存太小了吗?在学习objective-C的这个阶段,我需要一个内存管理工具

谢谢

最佳答案

您的(detailNav 的)过度保留还不是泄漏,因为它仍然被 splitViewController.viewControllers 引用。这就是 Instruments 不会将其显示为泄漏的原因。

Instruments 不会标记过度保留(它不能)。只有当您的对象被孤立时,即在所有其他非泄漏对象都释放了它们的引用之后,Instruments 才会将其标记为泄漏。

关于objective-c - 如何检测 Objective-C 中的变量是否未被释放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5893290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com