ios View Controller不断占用内存 [英] ios view controllers keep staking in memory

查看:153
本文介绍了ios View Controller不断占用内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉ObjectiveC.我正在开发我的第一个应用程序. -它基本上由2个视图控制器组成,我使用模式搜索在它们之间进行切换.主vc是一个菜单,它为每个菜单项加载具有不同属性的第二vc. -我注意到当我从一个vc切换到另一个vc时,内存一直在增加.这是我尝试解决的问题,但没有任何效果,而且看起来也不干净.

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?

推荐答案

问题是您正在双向使用模态搜索 .不要那样做您每次都只是在创建一个新的视图控制器:视图控制器彼此叠放.模态选择的反面(毕竟实际上是presentViewController:animated:)不是另一个模态选择.它是dismissViewControllerAnimated:(或者增加了一些复杂性,是放松的选择).

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

这篇关于ios View Controller不断占用内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆