I have found a strange memory leak problem. In my AppDelegate
, I set the
self.window.rootViewController = loginViewController;
After setting the rootViewController
point to loginViewController
,and I finish the login logic.Then I go to my homeViewController
, I call AppDelegate to change its rootViewController:
[UIApplication shareApplication].delegate.window.rootViewController = homeViewController;
However, I notice the -(void)dealloc
in loginViewController
is not called, i think a memory leak happen. After I search many similar question and test and test. I found that if I put the code in the same queue
, memomy leak is disappear. For example,
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
I really wonder why it is?
and more loginViewController
is local variable