【发布时间】:2015-02-16 18:54:32
【问题描述】:
我正在使用UIImageView+AFNetworking,以便从UITableView 中的URL 下载和显示图像。一切都很好,我的问题是关于这个调用实现的缓存元素和分配。
在使用工具来跟踪内存时,我发现当我滚动时,我最大的内存分配很快就变成了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) {
}];
【问题讨论】:
标签: uitableview uiimageview afnetworking nsurlcache image-caching