Memory being retained during concurrency #1300
-
ProblemView "ComposableCameraApp.swift" Gist In my dependency, Side Quest I'm sending the Is there a more efficient approach to updating view dependent state without running it through the reducer for high volume state changes? I greatly appreciate any corrections to my approach. Thank you for your time. Ouput
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @p-larson! // private var feed: CGImage! // Removed
func captureOutput(
_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer,
from connection: AVCaptureConnection
) {
if let imageBuffer = sampleBuffer.imageBuffer {
var image: CGImage?
VTCreateCGImageFromCVPixelBuffer(imageBuffer, options: nil, imageOut: &image)
if let image = image {
self.continuation.yield(image)
}
}
} As I'm getting it, the objective is to exit this function the fastest possible, so the sample buffer can be reused. Deciding what to do with these images depends on your use case and you may find a few remarks about high-frequency actions here. Fortunately, you've already transformed this feed into an Another remark: you did set your queue to |
Beta Was this translation helpful? Give feedback.
Hey @p-larson!
I've checked your Gist, and after fixing a few issues around authorization status (it seems you're not calling
AVCaptureDevice.requestAccess(for: .video)
when the status is unauthorized), I've managed to get it in a working state by updating a little your delegate. I never really used the video part of AVFoundation, so I may be wrong, but I'm not getting why you keep a reference to thefeed
image in your delegate. If you write your buffer in a local variable instead, it seems to work: