Question

Whenever I add a new viewController my ObjectAlloc jumps up really high and never comes back down. Even after calling removeFromSuperview. Is this normal?

if((UIButton *) sender == gameArcadeBtn) {
        GameArcade *gameArcadeController = [[GameArcade alloc] 
                              initWithNibName:@"GameArcade" bundle:nil]; 
        self.gameArcade = gameArcadeController; 
        [gameArcadeController release]; 
        [self.view insertSubview:gameArcadeController.view atIndex:1];
    }
Was it helpful?

Solution

Instantiating a view always creates many objects.As long as this view is in memory or has not been autoreleased, the objects will remained alloced in memory. Thus, to answer your question, this is normal.

It sounds like you are worried about memory usage and while it is important to watch the object allocs so that it doesn't get too it is more important to find your app leaks.

Some memory management tips:
1) do lazy loading. Only load your views when the user asks for them, not all at the beginning of the app
2) remove everything that you possibly can when you dont need it anymore. This means doing tons of work in viewWillAppear and viewDidDisappear
3) learn about @properties and how it relates to autoreleasing, and do not use properties for everything.
4) As appealing as it is, avoid autorelease and manually release objects when you dont need them anymore.

OTHER TIPS

that's probably due to the fact that you're still retaining the view's controller in the class. try releasing that

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top