Search code examples
iosmemorymemory-managementmemory-leaksnszombie

two exact same code but one of the code has zombie issue


in rootviewcontroller this code is working fine

- (IBAction)gotoAboutGame:(id)sender
{
    aboutGame *aboutGameObj = [[aboutGame alloc]init];

    [UIView transitionFromView:self.view toView:aboutGameObj.view duration:2 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        [aboutGameObj release];
    }];

    [self release];
}

but from aboutgame when i am coming back to rootviewcontroller i am getting zombie attacks

- (IBAction)gotoMain:(id)sender
{
ViewController *viewControllerObj = [[ViewController alloc]init];

    [UIView transitionFromView:self.view toView:viewControllerObj.view duration:2 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
        [viewControllerObj release];
    }];

    [self release];
}

it shows the rootviewcontroller view but as i touch any button zombie attacks.


Solution

  • What class is this code in?

    This line looks very suspect to me

    [self release];
    

    Why it the object releasing itself? Surely the object that created it should be doing this.