【发布时间】:2011-05-04 10:41:09
【问题描述】:
我认为我的 UIImage 引起了一些泄漏。事实上,有很多图片被下载,我认为当我下载新图片时,它显示在上面是旧的,旧的不是dealloc或release...
// Create and posit the UIImage
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
NSLog(@"retain count 1 : %i", [imageView retainCount]);
imageView = [[UIImageView alloc] initWithImage:image];
NSLog(@"retain count 2 : %i", [imageView retainCount]);
//[imageView setImage:image];
//[imageView initWithImage:image];
imageView.frame = CGRectMake(0,64,320,367);
NSLog(@"retain count 3 : %i", [imageView retainCount]);
[self.view addSubview:imageView];
NSLog(@"retain count 4 : %i", [imageView retainCount]);
[imageView release];
NSLog(@"retain count 5 : %i", [imageView retainCount]);
NSLog(@"-----------------------");
那个代码给了我这个结果:
retain count 1 : 0
retain count 2 : 0
retain count 3 : 1
retain count 4 : 1
retain count 5 : 2
retain count 6 : 1
-----------------------
retain count 1 : 0
retain count 2 : 0
retain count 3 : 1
retain count 4 : 1
retain count 5 : 2
retain count 6 : 1
-----------------------
retain count 1 : 0
retain count 2 : 0
retain count 3 : 1
retain count 4 : 1
retain count 5 : 2
retain count 6 : 1
-----------------------
显然,该图像已发布,只有 1 个,但较旧的仍然在手机屏幕上.. 显然...
如果屏幕上有更多的图片,我该如何释放旧的图片???
感谢阅读我的问题!!!
【问题讨论】:
标签: iphone uiimageview uiimage memory-leaks