我正在尝试制作一个简单的应用程序,用户可以在其中浏览笔记,然后做一个测试。我将这些笔记作为图像呈现,图像将分配给
UIImageView
向用户展示。
- (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)上升。最终,应用程序会崩溃,我无法再启动应用程序了。
我以前从未遇到过内存泄漏问题,因此我不知道该怎么办。在过去的一个小时里,我一直在用谷歌搜索,但没有找到解决办法。所以我的问题是如何释放内存或减少内存使用。