iPhone 应用程序因 UIImage 动画而内存泄漏?设备上的问题测试

发布于 2024-09-04 10:03:02 字数 1418 浏览 4 评论 0原文

我有一个动画在模拟器中运行良好,但在设备上崩溃。我收到以下错误...

程序收到信号:“0”。 由于信号 10 (SIGBUS),调试器已退出。

一些调查表明 UIImage 没有被释放,并且存在内存泄漏。我对此很陌生,所以有人可以告诉我这是否是可能的原因?如果你也能告诉我如何解决它那就太棒了。

这些图像的尺寸为 480 像素 x 480 像素,每张大约 25kb。我的代码如下...

NSArray *rainImages = [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"rain-loop0001.png"],
                           [UIImage imageNamed:@"rain-loop0002.png"],
                           [UIImage imageNamed:@"rain-loop0003.png"],
                           [UIImage imageNamed:@"rain-loop0004.png"],
                           [UIImage imageNamed:@"rain-loop0005.png"],
                           [UIImage imageNamed:@"rain-loop0006.png"],  
                           //more looping images
                           [UIImage imageNamed:@"rain-loop0045.png"],
                           [UIImage imageNamed:@"rain-loop0046.png"],
                           [UIImage imageNamed:@"rain-loop0047.png"],
                           [UIImage imageNamed:@"rain-loop0048.png"],
                           [UIImage imageNamed:@"rain-loop0049.png"],
                           [UIImage imageNamed:@"rain-loop0050.png"],
                           nil];


    rainImage.animationImages = rainImages;
    rainImage.animationDuration = 4.15/2;
    rainImage.animationRepeatCount = 0;
    [rainImage startAnimating];
    [rainImage release];

谢谢

I have an animation which works fine in the simulator but crashes on the device. I am getting the following error...

Program received signal: “0”.
The Debugger has exited due to signal 10 (SIGBUS)

A bit of investigating suggests that the UIImages are not getting released and I have a memory leak. I am new to this so can someone tell me if this is the likely cause? If you could also tell me how to solve it then that would be amazing.

The images are 480px x 480px and about 25kb each. My code is below...

NSArray *rainImages = [NSArray arrayWithObjects:
                           [UIImage imageNamed:@"rain-loop0001.png"],
                           [UIImage imageNamed:@"rain-loop0002.png"],
                           [UIImage imageNamed:@"rain-loop0003.png"],
                           [UIImage imageNamed:@"rain-loop0004.png"],
                           [UIImage imageNamed:@"rain-loop0005.png"],
                           [UIImage imageNamed:@"rain-loop0006.png"],  
                           //more looping images
                           [UIImage imageNamed:@"rain-loop0045.png"],
                           [UIImage imageNamed:@"rain-loop0046.png"],
                           [UIImage imageNamed:@"rain-loop0047.png"],
                           [UIImage imageNamed:@"rain-loop0048.png"],
                           [UIImage imageNamed:@"rain-loop0049.png"],
                           [UIImage imageNamed:@"rain-loop0050.png"],
                           nil];


    rainImage.animationImages = rainImages;
    rainImage.animationDuration = 4.15/2;
    rainImage.animationRepeatCount = 0;
    [rainImage startAnimating];
    [rainImage release];

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凶凌 2024-09-11 10:03:03

我很确定你会崩溃,因为 [NSArray arrayWithObjects:] 返回一个自动释放的对象,你将其存储到 rainImage 中。然后在底部你再次释放rainImage,从而过度释放它。

I'm pretty sure you're crashing because [NSArray arrayWithObjects:] returns an auto-released object which you're storing to rainImage. Then at the bottom you're releasing rainImage again, thus over releasing it.

稀香 2024-09-11 10:03:03

问题的根源是您的主内存不足,因为内存中有太多解压缩的图像,请参阅我对 uiimage-animation-causing-app-to-crash-memory-leaks 因为您不应该使用 UIImageView.animationImages。

The root of the problem is that you are running out of main memory because you have too many decompressed images in memory, see my answer to uiimage-animation-causing-app-to-crash-memory-leaks for the reason you should not be using UIImageView.animationImages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文