2

我有一个 UICollectionViewCell,其中有一个 UIImageView abd 我正在使用 AFNetworking UIImageView 类别来帮助我加载图像。我已经分析了我的应用程序,似乎内存峰值超过了顶部,它只是在通过分配工具下的 Instruments 对其进行分析后不断增加。

在此处输入图像描述

我不确定这里发生了什么以及如何解决这个问题。单元格一直在重复使用,但只是这些图像可能没有从缓存中清除或其他什么。这是我如何使用它的一些代码,它非常简单:

  NSURLRequest *imageURLRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:imageURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];

  [self.imageView_ setImageWithURLRequest:imageURLRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
        weakSelf.imageView_.image = image;
        weakSelf.imageView_.alpha = 0.0;
        [UIView animateWithDuration:0.3 animations:^{
            weakSelf.imageView_.alpha = 1.0;
        }];

    } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {

    }];

如果我删除此代码来下载图像,那么内存占用会更小。关于可能导致这种情况的任何想法?

4

1 回答 1

1

尝试将其包装在autoreleasepool中并检查您的内存使用情况

@autoreleasepool {
    // Code that creates autoreleased objects.
}
于 2013-01-24T19:30:25.973 回答