我的记忆和动画图像有问题。首先,我正在使用 ARC。在我的初始屏幕上,我有大约 60 个要制作动画的图像。我正在使用此代码进行动画:
NSMutableArray *images = [[NSMutableArray alloc] init];
int animationImageCount = 61;
for (int i = 1; i < animationImageCount; i++) {
[images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"s-%d", i]]];
}
self.fullAnimatedImage = [UIImage imageNamed:[NSString stringWithFormat:@"s-%d", animationImageCount - 1]];
self.animatedImageView.image = self.fullAnimatedImage;
self.animatedImageView.animationImages = [NSArray arrayWithArray:images];
self.animatedImageView.animationDuration = images.count/30;
self.animatedImageView.animationRepeatCount = 1;
[self.animatedImageView startAnimating];
// since there is no official callback method when UIImageView animation completes,
// we can just call a method after animation time has passed
[self performSelector:@selector(animationFinished) withObject:nil
afterDelay:self.animatedImageView.animationDuration];
问题是内存消耗约为300 MB,当然在iPhone 4上会崩溃。当我注释掉那部分代码时,内存消耗约为40 MB,没关系。我尝试将图像属性设置为 nil,但什么也没有。我试过把它放进去@autoreleasepool {}
但它不会发布其内容。您知道如何优化这个吗?
你应该尝试更换[UIImage imageNamed:]
with [UIImage imageWithContentsOfFile:]
.
来自文档:
如果您有一个仅显示一次的图像文件,并且希望确保它不会添加到系统缓存中,那么您应该使用 imageWithContentsOfFile: 创建图像。这将使您的一次性图像远离系统图像缓存,从而有可能改善应用程序的内存使用特性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)