Browse Source

Ensure the frame image instance dealloc in main thread

qibian 3 years ago
parent
commit
40908b03b9
1 changed files with 8 additions and 0 deletions
  1. 8 0
      Sources/Views/AnimatedImageView.swift

+ 8 - 0
Sources/Views/AnimatedImageView.swift

@@ -562,6 +562,14 @@ extension AnimatedImageView {
 
             let previousFrame = animatedFrames[previousFrameIndex]
             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
                 guard let currentAnimatedFrame = animatedFrames[index] else { return }