From 24d09d38831e145bc26fea6df9123b842ece1f9f Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Fri, 24 Jun 2022 12:05:07 +0200 Subject: [PATCH] Fix ContentViewModel deallocation --- Caps/Camera/ContentViewModel.swift | 14 ++++++++------ Caps/Camera/FrameManager.swift | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Caps/Camera/ContentViewModel.swift b/Caps/Camera/ContentViewModel.swift index 68f999c..d047921 100644 --- a/Caps/Camera/ContentViewModel.swift +++ b/Caps/Camera/ContentViewModel.swift @@ -8,15 +8,17 @@ class ContentViewModel: ObservableObject { @Published var frame: CGImage? @Published var image: UIImage? - private let context = CIContext() - - private let cameraManager = CameraManager.shared - private let frameManager = FrameManager.shared + private var cameraManager: CameraManager { + .shared + } + private var frameManager: FrameManager { + .shared + } init() { setupSubscriptions() } - + func setupSubscriptions() { frameManager.image = nil frameManager.current = nil @@ -34,7 +36,7 @@ class ContentViewModel: ObservableObject { } let ciImage = CIImage(cgImage: image) - return self.context.createCGImage(ciImage, from: ciImage.extent) + return FrameManager.shared.context.createCGImage(ciImage, from: ciImage.extent) } .assign(to: &$frame) diff --git a/Caps/Camera/FrameManager.swift b/Caps/Camera/FrameManager.swift index 64a7d75..9edc411 100644 --- a/Caps/Camera/FrameManager.swift +++ b/Caps/Camera/FrameManager.swift @@ -5,6 +5,8 @@ import UIKit class FrameManager: NSObject, ObservableObject { static let shared = FrameManager() + + let context = CIContext() @Published var current: CVPixelBuffer?