2014-03-04 20 views
0

我在应用程序加载并显示其启动屏幕后,我正在做一个简单的png动画。该动画在模拟器中运行,但不在实际的iPhone上,由于内存压力而终止(启动屏幕首先加载)。在调试中,内存以指数级增加至200MB,直至崩溃。仪器显示没有泄漏,全部堆和匿名Vm 9.61 MB。动画在iPhone上完全不显示。即使使用ARC和imageFilePath,动画也终止内存

我已经停止使用imageNamed设置其他帮助主题所建议的动画图像和使用的imageFilePath。它的工作原理和图像在模拟器上加载。我只是不确定还有什么要做。非常感谢帮助。

在didFinishLaunchingWithOptions:

[self.window makeKeyAndVisible]; 
self.animationView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; 
NSArray *animationArray = [[NSArray alloc] initWithObjects: 
[UIImage imageFromMainBundleFile:@"/Splash_00000.png"], 
[UIImage imageFromMainBundleFile:@"/Splash_00001.png"], 

//有其中约150所以我会忽略其余

         nil]; 

self.animationView.animationImages = animationArray; 
self.animationView.animationDuration = 5.0f; 
self.animationView.animationRepeatCount = 1; 
[self.animationView startAnimating]; 
[self.window addSubview:self.animationView]; 
[self.window bringSubviewToFront:self.animationView]; 

如果它的需要,这是方法我使用,我从另一个线程获得:

+(UIImage*)imageFromMainBundleFile:(NSString*)aFileName 
{ 
    NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; 
    return [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@", bundlePath, aFileName]]; 
} 
+0

*“这里约有150个”*。那就是你的问题。 –

回答

2

暂时忽略闪屏不是recommended,你没有泄漏,但你没有堆(这是它在模拟器上工作的原因)。

这些图像中的每一个都属于该数组,并且在动画完成后很长一段时间才会被ARC释放。请记住,在磁盘上压缩时,PNG将在内存中解压缩。

解决方案 - 有一对夫妇在想什么。

  1. 分割动画成离散阶段的序列,并且确保 该图像各相之间释放(使用@autoreleasepool
  2. 更为现实的,渲染动画作为电影和播放 代替(不太可能在相间断断续续)
+0

谢谢!我很欣赏答案!我现在将它渲染成一部电影。 –

相关问题