ios view controllers keep staking in memory

杀马特。学长 韩版系。学妹 提交于 2020-01-05 12:14:10

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/22279104/ios-view-controllers-keep-staking-in-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!