【发布时间】:2015-06-04 13:04:13
【问题描述】:
我在我的一个屏幕上使用 SDWebImage 异步显示大约 100 个网址。
当我尝试显示来自 url 的所有图像时,我遇到了内存负载问题。
我有一个 UIScrollView 并且我有一个 UIImageView 动态添加了所有 100 个 Uibutton。
现在我的要求是,当用户在特定级别放大 UIScrollView 时,我需要在 UIbutton 中显示图像,当我开始使用以下代码将图像从服务器显示到该按钮时,它会崩溃并出现内存警告。
[btn sd_setImageWithURL:[NSURL URLWithString:busOwner.WhiteLargeLogoURL] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:placeHolderImage]];
谁能告诉我,我该如何解决这个内存问题,并且还可以同时向所有 100 个按钮显示图像?
我也尝试过使用 uiiamgeView 而不是 uiButton,我也尝试过使用
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(queue, ^{
// Perform non main thread operation
for (BusinessOwnerEntity *busOwner in arrBusOwner) {
NSURL *url = [NSURL URLWithString:busOwner.WhiteLargeLogoURL];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadImageWithURL:url options:SDWebImageProgressiveDownload progress:^(NSInteger receivedSize, NSInteger expectedSize) {
NSLog(@"REcieved File %ld",(long)receivedSize);
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
}];
}
dispatch_sync(dispatch_get_main_queue(), ^{
// perform main thread operation
});
});
之前下载图片,但这里也崩溃了..
【问题讨论】:
标签: objective-c memory-leaks ios8 sdwebimage didreceivememorywarning