Authored by Bogdan Poplauschi
Committed by GitHub

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
@@ -99,11 +99,15 @@ typedef void(^SDWebImageNoParamsBlock)(void); @@ -99,11 +99,15 @@ typedef void(^SDWebImageNoParamsBlock)(void);
99 99
100 FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain; 100 FOUNDATION_EXPORT NSString *const SDWebImageErrorDomain;
101 101
102 -#ifndef dispatch_main_async_safe  
103 -#define dispatch_main_async_safe(block)\  
104 - if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\ 102 +#ifndef dispatch_queue_async_safe
  103 +#define dispatch_queue_async_safe(queue, block)\
  104 + if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(queue)) == 0) {\
105 block();\ 105 block();\
106 } else {\ 106 } else {\
107 - dispatch_async(dispatch_get_main_queue(), block);\ 107 + dispatch_async(queue, block);\
108 } 108 }
109 #endif 109 #endif
  110 +
  111 +#ifndef dispatch_main_async_safe
  112 +#define dispatch_main_async_safe(block) dispatch_queue_async_safe(dispatch_get_main_queue(), block)
  113 +#endif
@@ -106,7 +106,7 @@ static char TAG_ACTIVITY_SHOW; @@ -106,7 +106,7 @@ static char TAG_ACTIVITY_SHOW;
106 } 106 }
107 dispatch_queue_t targetQueue = shouldUseGlobalQueue ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) : dispatch_get_main_queue(); 107 dispatch_queue_t targetQueue = shouldUseGlobalQueue ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0) : dispatch_get_main_queue();
108 108
109 - dispatch_async(targetQueue, ^{ 109 + dispatch_queue_async_safe(targetQueue, ^{
110 [sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock]; 110 [sself sd_setImage:targetImage imageData:targetData basedOnClassOrViaCustomSetImageBlock:setImageBlock];
111 dispatch_main_async_safe(callCompletedBlockClojure); 111 dispatch_main_async_safe(callCompletedBlockClojure);
112 }); 112 });