Understanding addSubview: memoryLeak

Posted by Leandros on Stack Overflow See other posts from Stack Overflow or by Leandros
Published on 2014-05-27T21:20:10Z Indexed on 2014/05/27 21:25 UTC
Read the original article Hit count: 326

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).

© Stack Overflow or respective owner

Related posts about ios

Related posts about objective-c