Sfoglia il codice sorgente

Merge pull request #2419 from darkbrewx/fix/network-metrics-sessiontask-retain-cycle

Fix retain cycle in ImageDownloader when transferring network metrics
Wei Wang 6 mesi fa
parent
commit
e04d865097
1 ha cambiato i file con 2 aggiunte e 2 eliminazioni
  1. 2 2
      Sources/Networking/ImageDownloader.swift

+ 2 - 2
Sources/Networking/ImageDownloader.swift

@@ -427,7 +427,7 @@ open class ImageDownloader: @unchecked Sendable {
             return downloadTask
         }
 
-        sessionTask.onTaskDone.delegate(on: self) { (self, done) in
+        sessionTask.onTaskDone.delegate(on: self) { [weak sessionTask] (self, done) in
             // Underlying downloading finishes.
             // result: Result<(Data, URLResponse?)>, callbacks: [TaskCallback]
             let (result, callbacks) = done
@@ -449,7 +449,7 @@ open class ImageDownloader: @unchecked Sendable {
 
                     self.reportDidProcessImage(result: result, url: context.url, response: response)
 
-                    let imageResult = result.map { ImageLoadingResult(image: $0, url: context.url, originalData: data, metrics: sessionTask.metrics) }
+                    let imageResult = result.map { ImageLoadingResult(image: $0, url: context.url, originalData: data, metrics: sessionTask?.metrics) }
                     let queue = callback.options.callbackQueue
                     queue.execute { callback.onCompleted?.call(imageResult) }
                 }