我是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进行的。您是否在输出中收到了内存警告日志?如果没有,那么你很好。除此之外,我认为这很正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句