R – iPhone – dealloc subview UIViewController when removeFromSuperview

deallociphonememorymemory-managementuiviewcontroller

I have several buttons on my main UIViewController (main menu) that creates and adds a subview UIViewController on top of the main menu. When I remove the subview the memory from that controller is not released. How can I release that subviews memory instantly?

Does anyone have an example? This would solve all my problems! Thanks in advance.

Here is how I add a subview

if((UIButton *) sender == gameClassicBtn) {
        GameClassic *gameClassicController = [[GameClassic alloc] 
                             initWithNibName:@"GameClassic" bundle:nil]; 
        self.gameClassic = gameClassicController;
        [gameClassicController release]; 
        [self.view insertSubview:gameClassicController.view atIndex:1];
    }

Best Answer

Based on the code you provided there could be at least two places the UIViewController is being retained - one by the view heirarchy (self.view) and the other by a member variable (self.gameClassic). It sounds like you're only releasing the view heirarchy reference but not the member variable. If you release the latter does it deallocate the UIViewController?