iOS应用内存使用量在Xcode中持续增长
发布时间:2020-12-14 17:22:49 所属栏目:百科 来源:网络整理
导读:我是iOS编程的新手,我刚刚构建了一个iPhone应用程序,可以向用户提问并返回答案.构建环境是OS X 10.9和 Xcode 5.0.2.每次启动iPhone模拟器时,Debug Navigator都会显示内存使用量为13.5mb,但即使在我返回主屏幕后它也会继续运行.一分钟后,内存使用量将稳定在17
我是iOS编程的新手,我刚刚构建了一个iPhone应用程序,可以向用户提问并返回答案.构建环境是OS X 10.9和
Xcode 5.0.2.每次启动iPhone模拟器时,Debug Navigator都会显示内存使用量为13.5mb,但即使在我返回主屏幕后它也会继续运行.一分钟后,内存使用量将稳定在17.5mb左右.这是正常的行为还是我需要添加一些内存管理代码?
#import "QuizViewController.h" @interface QuizViewController () @property (nonatomic) int currentQuestionIndex; @property (nonatomic,copy) NSArray *questions; @property (nonatomic,copy) NSArray *answers; @property (nonatomic,weak) IBOutlet UILabel *questionLable; @property (nonatomic,weak) IBOutlet UILabel *answerLable; @end @implementation QuizViewController - (instancetype) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self){ self.questions = @[@"From what is cognac made?",@"What is 8 + 8 ?",@"What is the capital of Minnesota?"]; self.answers = @[@"Grapes",@"16",@"St.Paul"]; } return self; } - (IBAction)showQuestion:(id)sender { self.currentQuestionIndex++; if (self.currentQuestionIndex == [self.questions count]){ self.currentQuestionIndex = 0; } NSString *question = self.questions[self.currentQuestionIndex]; self.questionLable.text = question; self.answerLable.text = @"???"; } - (IBAction)showAnswer:(id)sender { NSString *answer = self.answers[self.currentQuestionIndex]; self.answerLable.text = answer; } @end 解决方法
使用ARC自动进行内存管理.您是否收到了输出中的内存警告日志?如果没有,那么你没事.除此之外,我认为这是正常的.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |