Merge pull request #2093 from dreampiggy/fix_completion_block_memory_called_next_runloop

Fix that completion block and set image block are called asynchronously for UIView+WebCache
This commit is contained in:
Bogdan Poplauschi 2017-11-03 23:49:28 +02:00 committed by GitHub
commit 821c2f3b8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -99,11 +99,15 @@ typedef void(^SDWebImageNoParamsBlock)(void);
FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain;
#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\
#ifndef dispatch_queue_async_safe
#define dispatch_queue_async_safe(queue, block)\
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(queue)) == 0) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
dispatch_async(queue, block);\
}
#endif
#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
#endif

View File

@ -106,7 +106,7 @@ static char TAG_ACTIVITY_SHOW;
}
dispatch_queue_t targetQueue = shouldUseGlobalQueue ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) : dispatch_get_main_queue();
dispatch_async(targetQueue, ^{
dispatch_queue_async_safe(targetQueue, ^{
[sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock];
dispatch_main_async_safe(callCompletedBlockClojure);
});