没有在 ARC 应用程序上调用 Dealloc [英] Dealloc not being called on ARC app

查看:22
本文介绍了没有在 ARC 应用程序上调用 Dealloc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController 被推送到容器控制器然后弹出,使用分配工具,我可以看到视图控制器随后被销毁.但是,永远不会到达控制器的 dealloc 中的断点.有谁知道为什么不调用 dealloc ?ARC是否可以在不调用dealloc的情况下销毁对象?

I have a UIViewController that is pushed onto a container controller and then popped off, and using the allocations instrument, I can see that the view controller is destroyed afterwards. However, a breakpoint in the controller's dealloc is never reached. Does anyone know why dealloc isn't called? Is it possible for ARC to destroy an object without calling dealloc?

另外,我禁用了 NSZombies(有人说这会导致 dealloc 不触发).

Also, I've disabled NSZombies (some have said that can cause dealloc not to fire).

Dealloc 没有做太多,只是打印到控制台,它永远不会被调用:

Dealloc doesn't do much, just prints to the console, and it never gets called:

- (void)dealloc{NSLog(@"Deallocating...");}

我不能发布容器控制器——它是专有的并且太复杂了.Dealloc 在某些控制器而不是其他控制器上被一致调用.如果我能找到时间,我会尝试发布一个重现问题的简化版本.

I can't post the container controller–it's proprietary and too complicated. Dealloc is called consistently on some controllers and not others. If I can find the time I will try and post a simplified version that reproduces the problem.

有什么方法可以验证 NSZombies 是否被禁用?

Is there any way to verify that NSZombies is disabled?

编辑2

我正在发布仪器的屏幕截图;在我看来,它正在正确释放.

I'm posting a screenshot from instruments; it looks to me like it's properly deallocating.

推荐答案

我刚刚遇到了类似的问题.你有没有提到自我"的地方?在我指的是自我"的初始化中,我有一些通知观察块.在 ARC 下,self 保留在块中.我的 dealloc 没有被调用,这就是我删除观察的地方.

I just ran across a similar issue. Do you have any blocks where you are referring to 'self'? I had some blocks for notification observation in my init where I was referring to 'self'. Under ARC self is retained in blocks. My dealloc wasn't getting called and that was where I was removing the observation.

诀窍是创建一个 __weak (iOS 5+) 或 __unsafe_unretained (iOS 4.x) 对您的self"的引用,并使用它来访问 self 或任何 _iVars(这些也会导致self"被保留)) 在块中.这是一个例子.

The trick is to create a __weak (iOS 5+) or __unsafe_unretained (iOS 4.x) reference to your 'self' and use that to access self or any _iVars (these will cause 'self' to be retained as well) in the block. Here's an example.

__unsafe_unretained TableViewController *weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextObjectsDidChangeNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
        if (weakSelf.tableView) {
            [weakSelf.tableView reloadData];
        }
    }];

这篇关于没有在 ARC 应用程序上调用 Dealloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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