iphone - 调试 AFNetworking 内存使用峰值

标签 iphone ios objective-c ipad afnetworking

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

enter image description here

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

  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) {

    }];

如果我删除这段代码来下载图像,那么内存占用就会小得多。知道是什么原因造成的吗?

最佳答案

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

@autoreleasepool {
    // Code that creates autoreleased objects.
}

关于iphone - 调试 AFNetworking 内存使用峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507415/

相关文章:

ios - 有没有办法在设备之间共享应用程序配置?

ios - 在 UILabel 上添加和删除动画

iphone - DataMan iPhone 应用程序如何在后台工作

ios - 无法调用电话

ios - 如何在没有动画的情况下放松 segue?

ios - 我如何在设置包中添加带有操作的按钮?

iphone - 退出 iPhone 应用程序时黑色状态栏变为白色

iOS : In app purchase. 产品根据用户类型付费或免费

ios - 如何从 Xcode 5 导入代码到 svn?

ios - 在我的 ScrollView 上显示 View