我的 iPhone 应用程序出现问题,当我在 iPod 上运行它时,它需要超过 10 分钟才会崩溃并关闭。因此,我查找了配置文件统计信息,并且似乎是高 Live Bytes,如下图所示:
任何人都可以帮助我减少此 Live Bytes 以避免崩溃?
编辑: 我在调用 viewDidLoad 时使用了三个 for 循环,这三个循环从引用中获取图像,所以我认为它会让应用程序崩溃?那么在不导致崩溃的情况下执行这三个 for 循环的替代方法是什么?
编辑2: 这是我的视图加载,每个循环从不同的文件夹中获取不同的图像,所有这些都是必要的
编辑 3:对于文件夹 a ,它有 100 张图片,其中一半是每张图片的缩略图,对于文件夹 b,30 张图片,最后是文件夹 c 90 张图片,其中一半是每张图片的缩略图,所有文件夹都在参考,所以它没有从互联网上获取任何图像......
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSInteger x = 6;
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *aPath = [resourcePath stringByAppendingPathComponent:@"a"];
NSArray *aDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:aPath error:nil];
for (NSString *tString in aDirContents) {
if ([tString hasSuffix:@".jpg"]) {
UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
[item setFrame:CGRectMake(x, 5, 60, 60)];
x += 63;
NSString *result = [tString substringToIndex:[tString length] - 4];
[item setTitle:result forState:UIControlStateNormal];
[item setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
[item setBackgroundImage:[UIImage imageNamed:tString] forState:UIControlStateNormal];
[item addTarget:self action:@selector(changeFont:) forControlEvents:UIControlEventTouchUpInside];
[aSlider addSubview:item];
}
}
aSlider.frame = CGRectMake(aSlider.frame.origin.x, aSlider.frame.origin.y, x, 69);
[aSliderContainer setContentSize:aSlider.frame.size];
x = 6;
NSString *bPath = [resourcePath stringByAppendingPathComponent:@"b"];
NSArray *bDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bPath error:nil];
for (NSString *tString in bDirContents) {
if ([tString hasSuffix:@".jpg"]) {
UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
[item setFrame:CGRectMake(x, 5, 60, 60)];
x += 63;
NSString *result = [tString substringToIndex:[tString length] - 4];
[item setTitle:result forState:UIControlStateNormal];
[item setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
[item setBackgroundImage:[UIImage imageNamed:tString] forState:UIControlStateNormal];
[item addTarget:self action:@selector(changeFont:) forControlEvents:UIControlEventTouchUpInside];
[bSlider addSubview:item];
}
}
bSlider.frame = CGRectMake(bSlider.frame.origin.x, bSlider.frame.origin.y, x, 69);
[bSliderContainer setContentSize:bSlider.frame.size];
// c Slider
x = 6;
NSString *cPath = [resourcePath stringByAppendingPathComponent:@"c"];
NSArray *cDirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:cPath error:nil];
for (NSString *tString in cDirContents) {
if ([tString hasSuffix:@".jpg"]) {
UIButton *item = [UIButton buttonWithType:UIButtonTypeCustom];
[item setFrame:CGRectMake(x, 5, 60, 60)];
x += 63;
NSString *result = [tString substringToIndex:[tString length] - 4];
[item setTitle:result forState:UIControlStateNormal];
[item setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
[item setBackgroundImage:[UIImage imageNamed:tString] forState:UIControlStateNormal];
[item addTarget:self action:@selector(changeFont:) forControlEvents:UIControlEventTouchUpInside];
[cSlider addSubview:item];
}
}
cSlider.frame = CGRectMake(cSlider.frame.origin.x, cSlider.frame.origin.y, x, 69);
[cSliderContainer setContentSize:cSlider.frame.size];
}