Browse Source

Invalidate session

onevcat 8 years ago
parent
commit
d3ccf32562
1 changed files with 5 additions and 0 deletions
  1. 5 0
      Sources/ImageDownloader.swift

+ 5 - 0
Sources/ImageDownloader.swift

@@ -198,6 +198,7 @@ open class ImageDownloader {
     /// You could change the configuration before a downloaing task starts. A configuration without persistent storage for caches is requsted for downloader working correctly.
     open var sessionConfiguration = URLSessionConfiguration.ephemeral {
         didSet {
+            session?.invalidateAndCancel()
             session = URLSession(configuration: sessionConfiguration, delegate: sessionHandler, delegateQueue: OperationQueue.main)
         }
     }
@@ -249,6 +250,10 @@ open class ImageDownloader {
         session = URLSession(configuration: sessionConfiguration, delegate: sessionHandler, delegateQueue: .main)
     }
     
+    deinit {
+        session?.invalidateAndCancel()
+    }
+    
     func fetchLoad(for url: URL) -> ImageFetchLoad? {
         var fetchLoad: ImageFetchLoad?
         barrierQueue.sync { fetchLoad = fetchLoads[url] }