每次更改UIImageView
的图像时,有大约 2-3 MB 添加到正在运行的内存中,如Xcode中左侧内存侧栏所示。这是我的代码,使用Xcode 5中的一个UIImageView
来循环显示几个图像:
- (void)PlayThoseImages{
if(CurrentImage < TotalNumOfImgaes){
CurrentImage++ ;
ImageName = @"Image .png" ;
NameString = [NSString stringWithFormat:@" %i",CurrentImageString] ;
ImageName = [ImageName stringByReplacingOccurrencesOfString:@" " withString: CurrentImageString] ;
BackgroundImage.image = [UIImage imageNamed:ImageName] ;
[self performSelector:@selector(PlayThoseImages) withObject:nil afterDelay:DelayInteger];
}
else{
ImageName = nil ;
CurrentImageString = nil ;
}
}
字符串,ImageName和CurrentImageString是标头中声明的全局NSStrings,以及整数。
延迟循环按预期运行,并且用于更改显示图像名称的字符串工作正常,但为什么,无论何时投影新图像(循环一次),内存都会增加 2 -3 MB ?我正在使用ARC
。
答案 0 :(得分:2)
imageNamed:如果您不喜欢要缓存的图片,请将图片添加到缓存中 imageWithContentsOfFile: