These days I am encountering a problem in relation to memory usage in my app that rarely causes this one to crash. I noticed from the memory inspector that it is caused by converting the CVPixelBuffer (of my camera) to UIimage. Below you can see the code I use:
extension UIImage {
public convenience init?(pixelBuffer: CVPixelBuffer) {
var cgImage: CGImage?
VTCreateCGImageFromCVPixelBuffer(pixelBuffer, options: nil, imageOut: &cgImage)
guard let cgImage = cgImage else {
return nil
}
self.init(cgImage: cgImage)
}
}
Any suggestions? Thanks in advance.