diff --git a/SDWebImage.podspec b/SDWebImage.podspec index d478d200..20792483 100644 --- a/SDWebImage.podspec +++ b/SDWebImage.podspec @@ -62,6 +62,6 @@ Pod::Spec.new do |s| 'USER_HEADER_SEARCH_PATHS' => '$(inherited) $(SRCROOT)/libwebp/src' } webp.dependency 'SDWebImage/Core' - webp.dependency 'libwebp' + webp.dependency 'libwebp', '~> 0.5' end end diff --git a/SDWebImage/SDImageCache.m b/SDWebImage/SDImageCache.m index 88b37c17..7eed11eb 100644 --- a/SDWebImage/SDImageCache.m +++ b/SDWebImage/SDImageCache.m @@ -11,31 +11,6 @@ #import "NSImage+WebCache.h" #import "SDWebImageCodersManager.h" -// See https://github.com/rs/SDWebImage/pull/1141 for discussion -@interface AutoPurgeCache : NSCache -@end - -@implementation AutoPurgeCache - -- (nonnull instancetype)init { - self = [super init]; - if (self) { -#if SD_UIKIT - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeAllObjects) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; -#endif - } - return self; -} - -- (void)dealloc { -#if SD_UIKIT - [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; -#endif -} - -@end - - FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { #if SD_MAC return image.size.height * image.size.width; @@ -96,7 +71,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) { _config = [[SDImageCacheConfig alloc] init]; // Init the memory cache - _memCache = [[AutoPurgeCache alloc] init]; + _memCache = [[NSCache alloc] init]; _memCache.name = fullNamespace; // Init the disk cache diff --git a/SDWebImage/SDWebImageDownloader.h b/SDWebImage/SDWebImageDownloader.h index ac7e5219..77a0ee8d 100644 --- a/SDWebImage/SDWebImageDownloader.h +++ b/SDWebImage/SDWebImageDownloader.h @@ -250,6 +250,7 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB * Invalidates the managed session, optionally canceling pending operations. * @note If you use custom downloader instead of the shared downloader, you need call this method when you do not use it to avoid memory leak * @param cancelPendingOperations Whether or not to cancel pending operations. + * @note Calling this method on the shared downloader has no effect. */ - (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations; diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 472559ca..3adc937c 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -108,6 +108,9 @@ } - (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations { + if (self == [SDWebImageDownloader sharedDownloader]) { + return; + } if (cancelPendingOperations) { [self.session invalidateAndCancel]; } else { diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 8fdab376..f8057041 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -419,7 +419,8 @@ didReceiveResponse:(NSURLResponse *)response image = [[SDWebImageCodersManager sharedInstance] decompressedImageWithImage:image data:&imageData options:@{SDWebImageCoderScaleDownLargeImagesKey: @(shouldScaleDown)}]; } } - if (CGSizeEqualToSize(image.size, CGSizeZero)) { + CGSize imageSize = image.size; + if (imageSize.width == 0 || imageSize.height == 0) { [self callCompletionBlocksWithError:[NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}]]; } else { [self callCompletionBlocksWithImage:image imageData:imageData error:nil finished:YES]; diff --git a/SDWebImage/SDWebImageGIFCoder.m b/SDWebImage/SDWebImageGIFCoder.m index 69172104..e05d1c0b 100644 --- a/SDWebImage/SDWebImageGIFCoder.m +++ b/SDWebImage/SDWebImageGIFCoder.m @@ -72,7 +72,7 @@ [frames addObject:frame]; } - NSUInteger loopCount = 0; + NSUInteger loopCount = 1; NSDictionary *imageProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(source, nil); NSDictionary *gifProperties = [imageProperties valueForKey:(__bridge_transfer NSString *)kCGImagePropertyGIFDictionary]; if (gifProperties) {