【发布时间】:2013-03-05 01:11:43
【问题描述】:
我正在尝试运行两个 UImageView,它们具有多个动画数组,它们根据用户所做的选择加载和制作动画。例如,这是一种方法:
-(void)initiateAnimations {
nullAnimation = [NSArray arrayWithObjects:
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0002" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0003" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0004" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0005" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0006" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0007" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0008" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0009" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0010" ofType:@"png"]], nil];
}
这里有一个IBAction调用动画方法:
-(IBAction)nullani {
player.animationImages = nullAnimation;
player.animationDuration = 0.50;
player.animationRepeatCount = 1;
[player startAnimating];
}
起初一切都很好,但请记住,我有大约 5-6 个其他动画数组,它们的图像大小大致相同。它们不是很大,从 12-80k .png 文件不等。当我尝试几次后制作动画时,我在输出中收到此错误:
2013-03-16 01:34:44.438 [3316:907] Received memory warning.
收到此消息后,加载的任何新动画都会使应用程序崩溃。 我通过 Instruments 运行它并找不到任何泄漏,并且在崩溃时输出没有给我任何信息。
这里有内存问题吗?我怎样才能摆脱这个问题?谢谢。
【问题讨论】:
-
图片有多大?在磁盘上不是以 kb 为单位的大小,如 .png 文件。以像素为单位?请记住,要显示图像,它们需要解压缩,因此可能与 12-80k 大小无关。这些是全屏图像吗?
-
请记住,内存泄漏并不是内存不足的唯一方法。你可能只是使用了太多。仪器会告诉您有关内存使用情况的哪些信息?每次启动动画时,您使用了多少字节?
-
@Nate 正常尺寸为 800x800,视网膜 1600x1600。其中大部分是空白的,主要内容是 75x400 左右,因为我的动画会增长/缩小/扩展。 800x800 充当舞台。
-
是的,这实际上是很多内存。同样,它不是压缩大小。是解压后的大小。有空白空间意味着图像可以被大量压缩,但是当它被大量解压缩时它并没有帮助。这可能只是您使用大量内存的情况。您是否需要始终保留所有 5-6 个阵列?你可以卸载/重新加载其中的一些吗?显然,当您再次需要它们时,您会牺牲速度。但是,您可能别无选择。
-
@Nate 不,不幸的是,这种技术是目前唯一有效的技术。我明白你现在在说什么。真可惜。
标签: ios animation memory uiimageview memory-leaks