我有一个不寻常的架构。有一个 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/