I need to push a view controller if the network is reachable. After the view controller is done, I want the memory to be released. The code I have is
Reachability* reachability = [Reachability reachabilityForInternetConnection];
BOOL isReachable = [reachability isReachable];
if(isReachable) {
ViewController *ppc = [[ViewController alloc] init];
[self.navigationController pushViewController:ppc animated:YES];
}
To pop the view controller, I use the following code inside (ViewController.m)
-(void) goBack {
[self.navigationController popViewControllerAnimated:YES];
}
When I see the memory usage in instruments, I don't see any memory being released when view controller is popped. So I modified the code as below.
@autoreleasepool {
Reachability* reachability = [Reachability reachabilityForInternetConnection];
BOOL isReachable = [reachability isReachable];
if(isReachable) {
ViewController *ppc = [[ViewController alloc] init];
[self.navigationController pushViewController:ppc animated:YES];
}
}
When I run above code, there is a memory drop the moment VC is pushed. But I expect the memory to drop when VC is popped. What am I doing wrong here.