Add a public API to allow user to invalidate URLSession used in SDWebImageDownloader to avoid memory leak on non-singleton instance
This commit is contained in:
parent
5872bd660b
commit
ae96351439
|
@ -246,4 +246,11 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
|
|||
*/
|
||||
- (void)createNewSessionWithConfiguration:(nonnull NSURLSessionConfiguration *)sessionConfiguration;
|
||||
|
||||
/**
|
||||
* Invalidates the managed session, optionally canceling pending operations.
|
||||
* If you use custom downloader instead of shared downloader, you need call this method when you do not use it to avoid memory leak
|
||||
* @param cancelPendingOperations Whether or not to cancel pending operations.
|
||||
*/
|
||||
- (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations;
|
||||
|
||||
@end
|
||||
|
|
|
@ -107,6 +107,14 @@
|
|||
delegateQueue:nil];
|
||||
}
|
||||
|
||||
- (void)invalidateSessionAndCancel:(BOOL)cancelPendingOperations {
|
||||
if (cancelPendingOperations) {
|
||||
[self.session invalidateAndCancel];
|
||||
} else {
|
||||
[self.session finishTasksAndInvalidate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self.session invalidateAndCancel];
|
||||
self.session = nil;
|
||||
|
|
Loading…
Reference in New Issue