瀏覽代碼

Ensure the frame image instance dealloc in main thread

qibian 3 年之前
父節點
當前提交
40908b03b9
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Sources/Views/AnimatedImageView.swift

+ 8 - 0
Sources/Views/AnimatedImageView.swift

@@ -562,6 +562,14 @@ extension AnimatedImageView {
 
 
             let previousFrame = animatedFrames[previousFrameIndex]
             let previousFrame = animatedFrames[previousFrameIndex]
             animatedFrames[previousFrameIndex] = previousFrame?.placeholderFrame
             animatedFrames[previousFrameIndex] = previousFrame?.placeholderFrame
+            // ensure the image dealloc in main thread
+            defer {
+                if let image = previousFrame?.image {
+                    DispatchQueue.main.async {
+                        _ = image
+                    }
+                }
+            }
 
 
             preloadIndexes(start: currentFrameIndex).forEach { index in
             preloadIndexes(start: currentFrameIndex).forEach { index in
                 guard let currentAnimatedFrame = animatedFrames[index] else { return }
                 guard let currentAnimatedFrame = animatedFrames[index] else { return }