【发布时间】:2018-03-05 09:01:50
【问题描述】:
我正在尝试制作一个简单的应用程序,用户可以在其中浏览笔记然后进行测验。我将此笔记作为图像呈现,并且图像将分配给UIImageView 以显示给用户。
在我看来确实加载了我主要是设置 UI。然后我将创建包含我的图像数组(注释)的数组
- (void)viewDidLoad {
UIColor *colourForNavigationBar = [self colorWithHexString:@"919D9F"];
[[UINavigationBar appearance] setBarTintColor:colourForNavigationBar];
UIColor *colourForBackground = [self colorWithHexString:@"F0F3F4"];
self.view.backgroundColor = colourForBackground;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:27.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = @"Notes";
[label sizeToFit];
UIColor *colourForButton = [self colorWithHexString:@"919D9F"];
self.previousButton.backgroundColor = colourForButton;
self.nextButton.backgroundColor = colourForButton;
finishedNotes = NO;
playerPlaying = NO;
arrayOfImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],
[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"],
[UIImage imageNamed:@"8.png"],
[UIImage imageNamed:@"9.png"],
[UIImage imageNamed:@"10.png"],
[UIImage imageNamed:@"11.png"],
[UIImage imageNamed:@"12.png"],
[UIImage imageNamed:@"13.png"],
nil];
}
然后是“下一个”按钮,允许用户继续下一个音符。下面是动作代码
- (IBAction)nextNote:(id)sender {
if (finishedNotes == YES) {
[self performSegueWithIdentifier:@"quizFromNotes" sender:self];
}
self.previousButton.enabled = YES;
stateOfPhoto++;
if (stateOfPhoto < 13) {
UIImage *image = [arrayOfImages objectAtIndex:stateOfPhoto-1];
self.imageView.image = image;
}
if (stateOfPhoto == 13) {
UIImage *image = [arrayOfImages objectAtIndex:stateOfPhoto-1];
self.imageView.image = image;
[self.nextButton setTitle:@"Begin Quiz" forState:UIControlStateNormal];
finishedNotes =YES;
}
if (playerPlaying == YES) {
[self.notesPlayer stop];
playerPlaying = NO;
}
}
一切都运行良好且顺利。但是,每当图像发生变化时,应用程序使用的内存就会增加几兆字节。下面是内存使用情况的照片。
从黑线开始,当我按下“下一步”按钮时,使用的内存会增加。它只是重复自己,直到用户继续进行测验。如果我结束测验并重新开始笔记,内存使用量将继续从之前的内存使用量 (73 mb) 上升。最终,该应用程序会崩溃,我无法再启动该应用程序。
我以前从未遇到过内存泄漏问题,因此我不知道该怎么办。在过去的一个小时里,我尝试使用谷歌搜索,但无法找到解决方案。所以我的问题是如何释放内存或减少内存使用量。
【问题讨论】:
标签: ios objective-c xcode memory