Change the token implementation to not retain the cancel token and completion block, which may it possible for user to retain the token in completion block without weak-strong dance.

This commit is contained in:
DreamPiggy 2019-09-30 02:17:22 +08:00
parent d0d19d23a2
commit 1096075ccb
2 changed files with 1 additions and 2 deletions

View File

@ -24,7 +24,7 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
@property (nonatomic, strong, nullable, readwrite) NSURL *url;
@property (nonatomic, strong, nullable, readwrite) NSURLRequest *request;
@property (nonatomic, strong, nullable, readwrite) NSURLResponse *response;
@property (nonatomic, strong, nullable, readwrite) id downloadOperationCancelToken;
@property (nonatomic, weak, nullable, readwrite) id downloadOperationCancelToken;
@property (nonatomic, weak, nullable) NSOperation<SDWebImageDownloaderOperation> *downloadOperation;
@property (nonatomic, weak, nullable) SDWebImageDownloader *downloader;
@property (nonatomic, assign, getter=isCancelled) BOOL cancelled;

View File

@ -238,7 +238,6 @@ static id<SDImageLoader> _defaultImageLoader;
context = [mutableContext copy];
}
// `SDWebImageCombinedOperation` -> `SDWebImageDownloadToken` -> `downloadOperationCancelToken`, which is a `SDCallbacksDictionary` and retain the completed block below, so we need weak-strong again to avoid retain cycle
@weakify(operation);
operation.loaderOperation = [self.imageLoader requestImageWithURL:url options:options context:context progress:progressBlock completed:^(UIImage *downloadedImage, NSData *downloadedData, NSError *error, BOOL finished) {
@strongify(operation);