我使用 是UIImageView+AFNetworking
为了从UITableView
. 一切都很好,我的问题是关于这个调用实现的缓存元素和分配。
在使用工具来跟踪内存时,我发现当我滚动时,我最大的内存分配很快变成了这个VM: Foundation
,看起来好像它正在以某种方式缓存我正在下载的图像。
当查看相同的图像但我从未看到它释放内存时,这对用户来说非常有用。(我还没有得到内存警告)。我只是想确保在需要时这个分配将在需要时释放。下面是那些的堆栈跟踪VM : Foundation
我是否需要监控这一点并在需要时释放缓存的内存以确保平滑滚动?或者还有什么我应该注意的以确保正确处理吗?
这是我在cellForRowAtIndexPath
调用setImageWithURLRequest
. 任何建议或改进将不胜感激。
NSString *imageURL = [NSString stringWithFormat:@"https://IMAGE-URL/%@",imageURL];
__weak MainTableViewCell *weakCell = cell;
NSURLRequest *urlRequest = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:imageURL]];
[cell.postImage setImageWithURLRequest:urlRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
MainTableViewCell *strongCell = weakCell;
strongCell.postImage.image = image;
[UIView animateWithDuration:.15 animations:^{
strongCell.postImage.alpha = 1;
}];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
}];