我在我的图片库和缩略图库中加载了很多图片,每次我按下按钮(部分)时,我都会用正确的seciont图片替换图片,自从第6-7次我这样做我的应用程序崩溃以来,一切都很好。因此,我尝试使用分配工具进行构建,每次我按下按钮时,我都会看到分配内存在增长!我一直希望看到的是堆栈内存分配,而不是initWithContentOfFile的增长。我做错了什么?
for (UIView *view in [scroller subviews]) {
[view removeFromSuperview];
}
for (UIView *view in [thumbnail subviews]) {
[view removeFromSuperview];
}
for (int i=1; i<numeroimg+1; i++) {
UIImageView *imagen = [[[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i]
ofType:@"jpg"]]]autorelease];
imagen.frame = CGRectMake((i-1)*1024, 0, 1024, 704);
[scroller addSubview:imagen];
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake((i-1)*210, 30, 200, 150)]autorelease];
[button setImage:[[UIImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i]
ofType:@"jpg"]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(pagina:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[thumbnail addSubview:button];
}发布于 2012-05-04 22:05:38
我做错了什么?
您正在使用+alloc创建一个镜像:
UIImageView *imagen = [[[UIImageView alloc] initWithImage:...但你永远不能释放imagen。
发布于 2012-05-08 00:27:10
尝试手动排出自动释放池
@autoreleasepool{
UIImageView *imagen = [[[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i]
ofType:@"jpg"]]]autorelease];
imagen.frame = CGRectMake((i-1)*1024, 0, 1024, 704);
[scroller addSubview:imagen];
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake((i-1)*210, 30, 200, 150)]autorelease];
[button setImage:[[UIImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%@%d",sezione,i]
ofType:@"jpg"]] forState:UIControlStateNormal];
[button addTarget:self action:@selector(pagina:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[thumbnail addSubview:button];
}https://stackoverflow.com/questions/10444987
复制相似问题