Understanding addSubview: memoryLeak
- by Leandros
I don't really understand, why this code leaks.
ParentViewController *parentController = [[ParentViewController alloc] init];
ChildViewController *childController = [[ChildViewController alloc] init];
[parentController containerAddChildViewController:childController];
[[self window] setRootViewController:parentController];
- (void)containerAddChildViewController:(UIViewController *)childViewController {
[self addChildViewController:childViewController];
[self.view addSubview:childViewController.view]; // Instruments is telling me, the leak occurs here!
[childViewController didMoveToParentViewController:self];
}
According to Instruments, this line: [self.view addSubview:childViewController.view]; is leaking. The whole code is called once in application:didFinishLaunchingWithOptions:, but it is shown that this code is responsible for 30 leaks (approx. 1.12 kB).