Merge pull request #2153 from dreampiggy/improve_duplicate_memory_warning

Remove the extra memory warning notification for AutoPurgeCache
This commit is contained in:
DreamPiggy 2018-01-11 16:59:07 +08:00 committed by GitHub
commit 5667d67fdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 26 deletions

View File

@ -11,31 +11,6 @@
#import "NSImage+WebCache.h" #import "NSImage+WebCache.h"
#import "SDWebImageCodersManager.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) { FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
#if SD_MAC #if SD_MAC
return image.size.height * image.size.width; return image.size.height * image.size.width;
@ -90,7 +65,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
_config = [[SDImageCacheConfig alloc] init]; _config = [[SDImageCacheConfig alloc] init];
// Init the memory cache // Init the memory cache
_memCache = [[AutoPurgeCache alloc] init]; _memCache = [[NSCache alloc] init];
_memCache.name = fullNamespace; _memCache.name = fullNamespace;
// Init the disk cache // Init the disk cache