Merge pull request #2789 from kinarobin/create_weak_cache_only_apply_to_iOS/tvOS_platform
Only create weak cache in iOS/tvOS platform.
This commit is contained in:
commit
834ce0875d
|
@ -16,9 +16,10 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext;
|
|||
@interface SDMemoryCache <KeyType, ObjectType> ()
|
||||
|
||||
@property (nonatomic, strong, nullable) SDImageCacheConfig *config;
|
||||
#if SD_UIKIT
|
||||
@property (nonatomic, strong, nonnull) NSMapTable<KeyType, ObjectType> *weakCache; // strong-weak cache
|
||||
@property (nonatomic, strong, nonnull) dispatch_semaphore_t weakCacheLock; // a lock to keep the access to `weakCache` thread-safe
|
||||
|
||||
#endif
|
||||
@end
|
||||
|
||||
@implementation SDMemoryCache
|
||||
|
@ -50,9 +51,6 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext;
|
|||
}
|
||||
|
||||
- (void)commonInit {
|
||||
self.weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsWeakMemory capacity:0];
|
||||
self.weakCacheLock = dispatch_semaphore_create(1);
|
||||
|
||||
SDImageCacheConfig *config = self.config;
|
||||
self.totalCostLimit = config.maxMemoryCost;
|
||||
self.countLimit = config.maxMemoryCount;
|
||||
|
@ -61,6 +59,9 @@ static void * SDMemoryCacheContext = &SDMemoryCacheContext;
|
|||
[config addObserver:self forKeyPath:NSStringFromSelector(@selector(maxMemoryCount)) options:0 context:SDMemoryCacheContext];
|
||||
|
||||
#if SD_UIKIT
|
||||
self.weakCache = [[NSMapTable alloc] initWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsWeakMemory capacity:0];
|
||||
self.weakCacheLock = dispatch_semaphore_create(1);
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(didReceiveMemoryWarning:)
|
||||
name:UIApplicationDidReceiveMemoryWarningNotification
|
||||
|
|
Loading…
Reference in New Issue