【问题标题】:iPhone app memory leak with UIImage animation? Problem testing on device带有 UIImage 动画的 iPhone 应用程序内存泄漏?设备问题测试
【发布时间】:2011-02-28 21:19:28
【问题描述】:

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

节目接收信号:“0”。 由于信号 10 (SIGBUS),调试器已退出

一些调查表明 UIImages 没有被释放,我有内存泄漏。我是新手,所以有人可以告诉我这是否是可能的原因吗?如果您也可以告诉我如何解决它,那将是惊人的。

图片大小为 480px x 480px,每张大约 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];

谢谢

【问题讨论】:

    标签: iphone memory-leaks uiimage imagenamed


    【解决方案1】:

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

    【讨论】:

    • 我已经尝试删除发布声明,但这并没有什么不同。上面的链接表明它正在使用导致我的问题的 imageNamed。感谢您对此的提醒:-)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-05-09
      • 1970-01-01
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      相关资源
      最近更新 更多