我使用SDWebImage
从服务器下载异步下载图像。我已经用iOS 8.1
测试了iPhone 5和5s中的应用程序并且工作正常,没有内存警告。但是我给客户端编译(使用iPhone 4s)并且在加载图像时他面临一些崩溃,不幸的是我没有iPhone 4,所以无法解决问题。我在使用iPhone5的乐器中进行了测试,这是几次运行后的屏幕截图。
这是我的下载图像代码
-(void)setImageWithUrl:(NSURL*)imgurl onImageView:(UIImageView*)image prograssive:(BOOL)progressive
{
__block UIActivityIndicatorView *activityIndicator;
__weak UIImageView *weakImageView = image;
SDWebImageOptions opt;
if (progressive) {
opt = SDWebImageProgressiveDownload;
}
else
opt = SDWebImageRetryFailed;
[image sd_setImageWithURL:imgurl placeholderImage:[UIImage imageNamed:@"default_image"] options:opt progress:^(NSInteger receivedSize, NSInteger expectedSize)
{
if (!activityIndicator)
{
[weakImageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = CGPointMake(weakImageView.frame.size.width /2, weakImageView.frame.size.height/2);
// activityIndicator.center = weakImageView.center;
[activityIndicator setBackgroundColor:[UIColor clearColor]];
[activityIndicator startAnimating];
}
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
}
我在didRecdeiveMemoryWarnig
方法
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
NSLog(@"memory warning received in voucher");
[[SDImageCache sharedImageCache] clearMemory];
[[SDImageCache sharedImageCache] cleanDisk];
[[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];
}
但它仍然在iPhone 4中崩溃。任何人都可以指导我做什么?
答案 0 :(得分:0)
听起来你的应用程序因内存压力而被杀死。也许尝试使用Autorelease Pool来缓解任何内存峰值,因为我认为你在 didReceiveMemoryWarning 中所做的事情在这些情况下并没有真正帮助。