3

I have a MyViewController, it's based on UIViewController, and I used it like the following code:

MyViewController *nextViewController = [[MyViewController alloc] init]; [self.navigationController pushViewController:nextViewController animated:YES]; [nextViewController release];

And in the MyViewController, with a user event, have the following code:

[self.navigationController popViewControllerAnimated:YES];

Now, I find that, the MyViewController's dealloc don't be called, but, when I switch the App to background, for example, pass the home button, the dealloc method has been called! This a big problem! There will be got a lot of MyViewController wouldn't be release, when user go to a MyViewController, and go back, again and again, and just, the lots of memory could be release only when the App goto background.

So, can anyone help me about this, thanks!

Echoldman
  • 143
  • 2
  • 7

1 Answers1

8

The obvious reason is that something is retaining your viewController. You will have to look closely at your code. Do you do anything that in your class that uses delegates, since they sometimes retain the delegate. NSURLConnection will retain your class, and so does NSTimer. You can scatter code in you class and log your class's retain count, and try to find out where. In the code you showed so far the retain could should just be 1, since the class is only retained by the navigation controller.

Also, before you pop your view, get a reference to it, pop it with NO animation, and then send it some message that has it report the retain count (this would be some new method you write). That new method could also log other things, like whether it has any timers going, NSURLConnections, etc.

David H
  • 40,852
  • 12
  • 92
  • 138