我有一个 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) {
}];
如果我删除这段代码来下载图像,那么内存占用就会小得多。知道是什么原因造成的吗?
最佳答案
尝试将其包裹在autoreleasepool中并检查你的内存使用情况
@autoreleasepool {
// Code that creates autoreleased objects.
}
关于iphone - 调试 AFNetworking 内存使用峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14507415/