UINavigationController leak / understanding popViewController

I have a navigation controller and a table view. When someone clicks on a table view, I do the following:

MyViewController *myViewController = [[MyViewController alloc] initWithImage:image];
[image release];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];

      

myViewController will save the image.

Now if I go back and forth in the NavigationController I get a leak because a new MyViewController is created every time and apparently popViewController does not release myViewController.

My question is: Why does popViewController not release the controller? How can I deal with this? Put myViewController as a member of my class and check if it already exists instead of creating it every time?

Thanks in advance for your help,

+2


a source to share


2 answers


Apparently the problem was that this code was being called on a different thread and then that thread must have another autoresource pool to allow autorelease to work properly.



+1


a source


I usually declare the viewController once in the class, highlight in init and click when needed. Then, in the controller with the viewpoint pressed, adjust the view toviewWillAppear:



0


a source







All Articles