【问题标题】:Memory warning and app crash when downloading images下载图像时出现内存警告和应用程序崩溃
【发布时间】:2012-11-28 22:48:29
【问题描述】:

我正在使用SDWebImage 库,图像大小约为 0.5 MB,点击UITableViewCell 时显示在detailView

详细视图中的代码:

- (void)configureView
{
    if (self.imageURL)
    {
        [self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
         {
             float percentDone = (float)receivedSize*200/(receivedSize+expectedSize);
             [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"Downloading... %0.0f%%", percentDone]];
             if (percentDone == 100) {
                 [SVProgressHUD showSuccessWithStatus:@"Loaded."];
             }
         }
                              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
         {

         }];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self configureView];
}

图像是否太大(半兆字节)? SDWebImage 缓存这些图片。

【问题讨论】:

  • 尝试评论 [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"Downloading... %0.0f%%", percentDone]];
  • 我马上给它,一秒钟重现崩溃
  • 没有崩溃日志,只有几次:收到内存警告。然后应用关闭
  • @MikhailViceman,我试图评论该行,内存警告和崩溃仍然发生。顺便说一句,崩溃不会在第一个图像显示时发生,但在几次之后。
  • 确保在关闭详细视图后发布图片

标签: iphone ios memory crash sdwebimage


【解决方案1】:

您说您在 viewDidUnload 中发布了 imageView.image,但在 ios6 上不推荐使用 viewDidUnload。视图不再被卸载..该方法可能没有被调用:)

didReceiveMemoryWarning做吧

【讨论】:

  • 我会尝试将UIImageView的IBOutlet设置为weak
  • 我已将 IBoutlet 属性设置为(非原子,弱)并在 didReceiveMemoryWarning 中将其设置为 nil,但我仍然收到内存警告和应用程序崩溃
  • 在 XCode 中使用 Profile,检测导致内存警告的原因。
【解决方案2】:

在 TABLEViewCell 中使用 SDWebImageProgressiveDownload 不是一个好主意,使用 SDWebImageRetryFailed 就可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多