I'm getting reports of memory leaks in my app, but I can't track down exactly what is happening. I have a function which takes out an old view and swaps in a new view. I'm not using NavControllers or any @properties; I'm managing my top-level window directly.
-(void)swapInView:(UIViewController*)newViewController
{
[currentViewer.view removeFromSuperview];
printf("Old viewController (%p) has count of %d; now releasing\n",
currentViewer, [currentViewer retainCount]);
[currentViewer release];
currentViewer = 0;
currentViewer = newViewController;
[currentViewer retain];
[mainWindow addSubview:currentViewer.view];
[mainWindow bringSubviewToFront:currentViewer.view];
}
When run the code, I show that the current view controller is being deallocated, and then my dealloc method for that view controller is getting called. But, Instruments/leaks still reports it as a leak. For instance, I get this print out:
Old viewController (0x119f80) has count of 1; now releasing
Deallocating WelcomeScreenViewController
I can verify from the address, that this is the same object being allocated previously.
My external code looks something like this:
MyViewController *theViewController = [[MyViewController alloc]
initWithNibName:nil
bundle:nil];
[GameMaster swapInNewView:theViewController];
[theViewController release];
Does anybody have any suggestions of how to track down what is going on? I'm using the 3.1.2 SDK, but I was also seeing this on earlier SDK's.