Merge pull request #3265 from RbBtSn0w/3.x

Fix SDWebImageCombinedOperation was leak.
This commit is contained in:
DreamPiggy 2021-09-30 17:30:18 +08:00 committed by GitHub
commit c7c1cde776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -148,6 +148,30 @@
@synchronized (self.runningOperations) {
[self.runningOperations addObject:operation];
/*
Fix: Memory bug
When the task is executed in a concurrent queue, when the user scrolls up and down in the List, the function call "sd_setImageWithURL:placeholderImage:options:progress:completed:" will be triggered to "SDWebImageCombinedOperation cancel",
and the real task will be Cancel was called, which caused the task to be executed in multi-threaded execution until the "operation.isCancelled" in "SDImageCache queryDiskCacheForKey:done:" was returned.
Through the principle of opening and closing, when we add, we guarantee that there must be a place to be removed.
Since the block supports the ability of external coverage, the approach here is the same as
operation.cancelBlock = ^{
[subOperation cancel];
This code does not conflict
There is a bug that SDWebImageCombinedOperation is not released.
*/
__weak __typeof(self) weakSelf = self;
operation.cancelBlock = ^{
__strong __typeof(weakSelf) strongSelf = weakSelf;
__strong __typeof(weakOperation) strongOperation = weakOperation;
if (strongOperation) {
[strongSelf.runningOperations removeObject:strongOperation];
}
};
}
NSString *key = [self cacheKeyForURL:url];