views:

39

answers:

1

Within my application I have 20 or so ViewControllers and Xibs that the user should be able to access. The problem is after looking at 5 or so of them the application crashes due to lack of memory. I have released all memory that I have allocated within the ViewControllers so I can only assume it's because its holding the memory of so many IBOutlets.

Heres the code I use to insert the views and at the top also how I remove them:

-(void)InsertUpperHall{
    [lowerHall.view removeFromSuperview];

    if(self.upperHall == nil)
    {
        UpperHall *upperController = [[UpperHall alloc] initWithNibName: @"UpperHall" bundle:nil];
        self.upperHall = upperController;
        [upperController release];
    }
    [self.view insertSubview: upperHall.view atIndex:0];
}

Any help would be greatly appreciated

+2  A: 

All IBOutlets that are retained properties need to be set to nil in viewDidUnload and dealloc.

I highly recommend:

Lou Franco
There is a great article explaining why you need to do this: http://weblog.bignerdranch.com/?p=95
Jergason