【发布时间】:2023-04-03 00:30:02
【问题描述】:
我有一个 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) {
}];
如果我删除此代码来下载图像,那么内存占用会更小。知道是什么原因造成的吗?
【问题讨论】:
-
您可以考虑直接流式传输到闪存存储...
-
这是什么意思?\
-
这意味着不是分配内存 (RAM) 来保存下载的图像,而是在“磁盘”上打开一个文件并将任何接收到的内容附加到该文件中。您不会使用那么多 RAM。
-
虽然我看到您只是使用 NSURLConnection 自动进行下载——也许可以选择将其下载到文件中。
-
-setImageWithURLRequest中有什么内容?
标签: iphone ios objective-c ipad afnetworking