Dealloc没有用ARC调用子视图

out*_*oll 1 objective-c uiviewcontroller uiview ios automatic-ref-counting

我有一个不常见的架构.有一个UIViewController和许多子视图.我使用UIView,如viewController和UIViewController进行过渡动画.

UIView有很多子视图,我在主窗口上推,我removeFromSuperview并且一切正常,但是子视图不能调用dealloc方法.我也尝试清理对象

- (void) dealloc {
    NSLog(@"ActivityShowVC dealloc");
    [showView removeFromSuperview];
    showView = nil;
}

这叫.

- (void) dealloc {
    NSLog(@"ActivityShowView dealloc");

    [mainScroll removeFromSuperview];

    [titleView setDelegate:nil];
    [titleView removeFromSuperview];
    titleView = nil;

    [photoView setDelegate:nil];
    [photoView removeFromSuperview];
    photoView = nil;

    [predictionView setDelegate:nil];
    [predictionView removeFromSuperview];
    predictionView = nil;

    [calendarView setDelegate:nil];
    [calendarView removeFromSuperview];
    calendarView = nil;

    [descriptionView setDelegate:nil];
    [descriptionView removeFromSuperview];
    descriptionView = nil;
}

但这有一些问题.

zap*_*aph 5

如果dealloc已实现但未调用,则会保留实例.您需要重新考虑对它的强引用.

除了释放资源之外,Dealloc不是做任何其他事情的好地方,因为实例不再具有完全功能,也不是完整状态.做以下事情:[showView removeFromSuperview];最好在解除分配之前明确完成.

正如@Greg所说,dealloc在ARC下不需要你正在做的大部分或全部.现在的子视图通常weak不需要明确的dealloc.实际上,它们可能已经消失,具体取决于视图层次结构的拆卸顺序.