在 iOS 5 上的 ARC 中,您能看到谁导致了发布吗?

发布于 2025-01-04 08:28:16 字数 346 浏览 4 评论 0原文

在我启用 ARC 的 iOS 5 项目中,我的一个对象被过早释放,因此当我稍后尝试访问它时,我得到一个空指针。在 ARC 之前,我会像这样简单地重写 release

-(oneway void)release {
    NSLog(@"-1");    //breakpoint goes here
    [super release];
}

然后在 NSLog 上添加一个断点并检查调用堆栈以查看是谁导致了释放。

如何查明谁在 ARC 下“调用”了发布? (“调用”可能是错误的词,因为编译器插入了释放调用,所以我的意思是“编译器插入释放调用的行在哪里?”)。

In my iOS 5 project with ARC enabled, one of my objects gets released prematurely, so when I try to get to it later I get a null pointer. Before ARC, I would have simply overridden release like this:

-(oneway void)release {
    NSLog(@"-1");    //breakpoint goes here
    [super release];
}

then added a breakpoint on the NSLog and inspected the call stack to see who is causing a release.

How do I find out who "called" release under ARC? ("Called" might be the wrong word since the compiler inserts the release calls, so what I mean is "where is the line that the compiler inserted a release call?").

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2025-01-11 08:28:16

如果您需要查看对象在何处发生保留、释放和自动释放,请使用仪器:

在仪器中运行,在分配中设置“记录引用计数”(您必须停止记录才能设置该选项)。导致问题代码运行,停止记录,搜索感兴趣的 ivar,向下钻取,您将能够看到所有保留、释放和自动释放发生的位置。

在此处输入图像描述

If you need to see where retains, releases and autoreleases occur for an object use instruments:

Run in instruments, in Allocations set "Record reference counts" on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for the ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文