ios - 使用 ARC 未在 subview 上调用 Dealloc

标签 ios objective-c uiview uiviewcontroller automatic-ref-counting

我有一个不寻常的架构。有一个 UIViewController 和许多 subview 。我使用 UIView 之类的 viewController 和 UIViewController 进行过渡动画。

UIView 有很多 subview ,我在主窗口上推送,我 removeFromSuperview 一切正常,但 subview 不调用 dealloc 方法。我也尝试清洁物体

-(无效)dealloc {
NSLog(@"ActivityShowVC dealloc");
[showView removeFromSuperview];
显示 View = 无;
}

这叫。

-(无效)dealloc {
NSLog(@"ActivityShowView dealloc");

[mainScroll removeFromSuperview];

[titleView setDelegate:nil];
[titleView removeFromSuperview];
标题 View = 无;

[照片 View setDelegate:nil];
[照片 View removeFromSuperview];
照片 View = 无;

[predictionView setDelegate:nil];
[predictionView removeFromSuperview];
预测 View = 无;

[日历 View setDelegate:nil];
[日历 View removeFromSuperview];
日历 View = 无;

[descriptionView setDelegate:nil];
[descriptionView removeFromSuperview];
描述 View = 无;
}

但这有一些问题。

最佳答案

如果 dealloc被实现并且没有被调用然后有一些东西保留了实例。你需要重新考虑对它的强引用。

Dealloc 不是一个除了释放资源之外做任何事情的好地方,因为实例不再完全正常运行或处于完整状态。执行以下操作:[showView removeFromSuperview];最好在解除分配之前明确完成。

正如@Greg 所说,您在 dealloc 中所做的大部分或全部工作在 ARC 下不需要。现在 subview 一般是weak所以不需要显式的dealloc。事实上,根据 View 层次结构的拆卸顺序,它们可能已经消失了。

关于ios - 使用 ARC 未在 subview 上调用 Dealloc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20774494/

相关文章:

ios - [super layoutSubviews] 的正确调用方式是什么?

iphone - UILabel 无法更新标签文本

ios - 不同设备上 int 类型的大小不同

ios - setNeedsDisplay 破坏了 UIView 的自动布局动画

iphone - 使用Core Animation的开门效果

iOS 的 MySQL 包装器

ios - 为什么 self.splitViewController == nil?

iphone - 从回调函数线程化时的“Just Leaking”

ios - 以编程方式创建具有颜色渐变的 UIView

ios - 使用键盘动画调整约束大小