将子视图添加到mainWindow会导致在从superview中删除时保留Controller

时间:2015-04-16 13:51:45

标签: ios

使用此代码:UIViewController(iPadHubVideoPlayer)在我超出范围时分配然后释放deallocs。

-(void)playiPadHubPlayer{
    iPadHubVideoPlayer *padHubVideoPlayer = [[iPadHubVideoPlayer alloc] init]; 
}

但是,如果我添加这些行来创建函数:

-(void)playiPadHubPlayer{
    iPadHubVideoPlayer *padHubVideoPlayer = [[iPadHubVideoPlayer alloc] init];
    AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];
    UIWindow *mainWindow = [appDelegate window];
    [mainWindow addSubview: padHubVideoPlayer.view];
    [padHubVideoPlayer.view removeFromSuperview];

}

然后,即使超出范围并且没有明显的指针,也永远不会调用UIViewController的dealloc方法。所以理论上我永远不会使用这种显示内容的方式而没有某种保留周期。关于为什么会发生这种情况的任何想法...... UIWindow会以某种方式保留它吗?

0 个答案:

没有答案