关于window.rootViewController的内存泄漏

时间:2016-07-13 07:50:53

标签: ios objective-c memory-leaks

我发现了一个奇怪的内存泄漏问题。在我的AppDelegate中,我设置了

self.window.rootViewController = loginViewController;

rootViewController点设置为loginViewController后,我完成了登录逻辑。然后我转到homeViewController,我调用AppDelegate来更改其rootViewController:

[UIApplication shareApplication].delegate.window.rootViewController = homeViewController;

但是,我注意到-(void)dealloc中的loginViewController没有被调用,我认为发生了内存泄漏。在我搜索了许多类似问题并进行测试和测试之后。我发现如果我把代码放在同一个queue中,memomy泄漏就会消失。例如,

NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
      self.window.rootViewController = loginViewController;
}];
[[NSOperationQueue mainQueue] addOperation:blockOperation];
NSBlockOperation *blockOperation = [NSBlockOperation blockOperationWithBlock:^{
      [UIApplication shareApplication].delegate.window.rootViewController = homeViewController;
}];
[[NSOperationQueue mainQueue] addOperation:blockOperation];

loginViewController dealloc is successful我真的好奇为什么会这样? 更多loginViewControllerlocal variable

0 个答案:

没有答案