'Memory leak issue virtual camera macOS, swift SwiftUI zoom caphost
We are developing a application with virtual camera plugin for macOS by using swiftUI & swift. It has also C++ & objective C library. When we use that plugin via zoom it remain stable 2/3 hours & memory consumption of caphost around 140-300 MB. After that memory consumption grows rapidly & after 6/7 hours, it becomes 10+ GB. This scenario is mostly for "Catalina - 10.15.7, Processor: Intel Core i5 Dual-core, Memory: 8 GB, GPU:Intel Iris”. Is there any idea about this memory leaking issue?
func videoCapture(_ capture: IBYVideoProcessor, didCapture pixelBuffer: CVPixelBuffer?, with sampleTimingInfo: CMSampleTimingInfo) {
guard var pixelBuffer = pixelBuffer, let queue = queue, CMSimpleQueueGetCount(queue) < CMSimpleQueueGetCapacity(queue) else {
return
}
if IBYDataManager.shared.settingInformation.isDontShowAnyAnalysisInformation == false || IBYVideoProcessor.shared.isEnableMLProcess == true {
var currentCGImage: CGImage?
var currentCIImage : CIImage? = nil
// var pixelInfo : IBYPixelBufferModel?
let pixelInfo : IBYPixelBufferModel? = IBYPixelBufferModel()
let request = VNDetectFaceRectanglesRequest { [weak self] (request, error) in
guard let observation = request.results?.first as? VNFaceObservation else {
if IBYDataManager.shared.settingInformation.isTurnOnIBYCamera == false {
let artwork = IBYPixelbufferArtwork()
artwork.render(into: &pixelBuffer)
}
let bottombar = IBYPixelbufferBottomBar()
bottombar.render(into: &pixelBuffer)
self?.sendInformation(information: pixelBuffer, with: sampleTimingInfo)
pixelInfo?.reset()
return
}
let width = CVPixelBufferGetWidth(pixelBuffer)
let height = CVPixelBufferGetHeight(pixelBuffer)
let faceBound = VNImageRectForNormalizedRect(observation.boundingBox, width, height)
pixelInfo?.face = faceBound
let renderer = IBYObservationRenderer(faceRect: faceBound)
renderer.render(into: &pixelBuffer)
let bottombar = IBYPixelbufferBottomBar()
bottombar.render(into: &pixelBuffer)
self?.sendInformation(information: pixelBuffer, with: sampleTimingInfo)
if pixelInfo?.isEnableMLProcess == true {
let mlOperation = IBYAnalysisOperation()
mlOperation.information = pixelInfo
IBYVisionManager.shared.addItemForMLProcessing(operation: mlOperation)
} else {
pixelInfo?.reset()
}
}
let isEnableMLProcess = IBYVideoProcessor.shared.isEnableMLProcess
if isEnableMLProcess == true {
IBYVideoProcessor.shared.isEnableMLProcess = false
}
VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: ¤tCGImage)
if let cgImage = currentCGImage {
currentCIImage = CIImage(cgImage: cgImage)
// pixelInfo = IBYPixelBufferModel()
pixelInfo?.cgImage = currentCGImage
pixelInfo?.ciImage = currentCIImage
pixelInfo?.isEnableMLProcess = isEnableMLProcess
guard let currentCIImage = currentCIImage else { return }
do {
let requestHandler = VNSequenceRequestHandler()
try requestHandler.perform([request], on:currentCIImage)
} catch let error as NSError {
log("IBY Camera: \(error)")
if IBYDataManager.shared.settingInformation.isTurnOnIBYCamera == false {
let artwork = IBYPixelbufferArtwork()
artwork.render(into: &pixelBuffer)
}
let bottombar = IBYPixelbufferBottomBar()
bottombar.render(into: &pixelBuffer)
self.sendInformation(information: pixelBuffer, with: sampleTimingInfo)
}
} else {
if IBYDataManager.shared.settingInformation.isTurnOnIBYCamera == false {
let artwork = IBYPixelbufferArtwork()
artwork.render(into: &pixelBuffer)
}
let bottombar = IBYPixelbufferBottomBar()
bottombar.render(into: &pixelBuffer)
self.sendInformation(information: pixelBuffer, with: sampleTimingInfo)
}
} else {
if IBYDataManager.shared.settingInformation.isTurnOnIBYCamera == false {
let artwork = IBYPixelbufferArtwork()
artwork.render(into: &pixelBuffer)
}
let bottombar = IBYPixelbufferBottomBar()
bottombar.render(into: &pixelBuffer)
self.sendInformation(information: pixelBuffer, with: sampleTimingInfo)
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|