sporadic
sporadic

Reputation: 11

ios view controllers keep staking in memory

I am new to Objective C. I am working on my first app. - It basically consists of 2 view controllers, and I use modal segue to switch between them. The main vc is a menu that loads up the 2nd vc with different attributes for each menu item. - I noticed that the memory keeps increasing when I switch from one vc to the other. This was my attempt to solve the issue but it doesn't make a difference and it doesn't look clean.

-(void)viewDidDisappear:(BOOL)animated{
    ViewController *me = self;
    me = nil;
}

What is the best practice to handle memory in a case like this?

Upvotes: 1

Views: 518

Answers (1)

matt
matt

Reputation: 535140

The problem is that you are using a modal segue in both directions. Don't do that. You are simply creating a new view controller each time: you have view controllers piling up on top of each other. The opposite of a modal segue (which is actually presentViewController:animated:, after all) is not another modal segue; it is dismissViewControllerAnimated: (or, with some added complexity, an unwind segue).

Upvotes: 2

Related Questions