title: UIViewController not being released when popped
body: <p>I have a table view that when a cell is selected it pushes a view controller onto the navigation stack:</p>
  
  <pre><code>SAPostTableViewController *postViewController = [[SAPostTableViewController alloc] initWithNibName:NSStringFromClass([SAPostTableViewController class]) bundle:nil];
  postViewController.site = site;
  [self.navigationController pushViewController:postViewController animated:YES];
  [postViewController release];
  </code></pre>
  
  <p>SAPostTableViewController has a static tableView which, and it's cells, are loaded from a nib.</p>
  
  <p>I have overridden the <code>initWithNibName:bundle:</code> method:</p>
  
  <pre><code>-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
          self.sections = [NSMutableDictionary dictionary];
      }
      return self;
  }
  </code></pre>
  
  <p><code>sections</code> is a retained property.</p>
  
  <p>In <code>viewDidLoad</code> of <code>SAPostTableViewController</code> I have this:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cellVisibiltyChanged:) name:@"SAStaticCellVisibiltyChanged" object:nil];
  }
  </code></pre>
  
  <p>and so to match in <code>viewDidUnload</code>:</p>
  
  <pre><code>- (void)viewDidUnload
  {
      [super viewDidUnload];
      [[NSNotificationCenter defaultCenter] removeObserver:self name:@"SAStaticCellVisibiltyChanged" object:nil];
  }
  </code></pre>
  
  <p>However when I press the back button in the navigation bar (all standard behaviour, no override) and <code>SAPostTableViewController</code> is popped, it doesn't call <code>viewDidUnload</code> or <code>dealloc</code>. So this means that if I then reselect the cell that pushes <code>SAPostTableViewController</code> it creates a new instance of <code>SAPostTableViewController</code> and repeating this back and forward just means the memory usage keeps increasing as the popped <code>SAPostTableViewController</code>s never get deallocated. (I know this by running Instruments on allocations)</p>
  
  <p>The weird thing is that if I release SAPostTableViewController twice then it works as I'd expect:</p>
  
  <pre><code>SAPostTableViewController *postViewController = [[SAPostTableViewController alloc] initWithNibName:NSStringFromClass([SAPostTableViewController class]) bundle:nil];
  postViewController.site = site;
  [self.navigationController pushViewController:postViewController animated:YES];
  [postViewController release];
  [postViewController release];
  </code></pre>
  
  <p>(If I add a third release statement, it crashes as I'd expect it to with just 2)</p>
  
  <p>I have resorted to using <code>retainCount</code> and stepped through the lines of code the are executed in the first line of the directly above code, the retainCount remains at 1. It jumps up between the first and second line, so I can't see anywhere it is being retain an extra time?</p>
  
  <p>The SAPostTableViewController is only used in this place, it is not a delegate of anything, nor does it have a delegate. </p>
  
  <p>How can I find a fix, or is it something simple I've missed?</p>
  
  <p>Here is what Instruments shows after pushing SAPostTableViewController just once (with only one release statement):
  <img src="https://i.stack.imgur.com/ym2eo.png" alt="enter image description here"></p>
  
  <p>And what it shows after navigating back and forth repeatedly (again, one release statement):
  <img src="https://i.stack.imgur.com/MgwXc.png" alt="enter image description here"></p>