UINavigationController leak/understanding popViewController
        Posted  
        
            by Kamchatka
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kamchatka
        
        
        
        Published on 2010-04-30T23:29:11Z
        Indexed on 
            2010/04/30
            23:47 UTC
        
        
        Read the original article
        Hit count: 965
        
Hello,
I have a navigation controller and a table view. When someone click on the table view, I do the following:
MyViewController *myViewController = [[MyViewController alloc] initWithImage:image];
[image release];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
myViewController will retain the image.
Now, if I go back and forth in the NavigationController, I get a leak because a new MyViewController gets created each time and apparently the popViewController doesn't release the myViewController.
My question: Why doesn't popViewController release the controller? How should I handle that? Put the myViewController as a member of my class and check if it already exists instead of creating it each time?
Thanks in advance for your help,
© Stack Overflow or respective owner