Memory issue when using Vision with camera

An app is using AVFoundation + Vision framework to detect rectangles in video stream from camera and allows user to take photo. I'm experiencing crash caused by memory issue only on iPhone 8 (iOS 12.1.2). Other devices like 5s, 6s, 6s+, X works fine.


This message is printed to Xcode console:

Message from debugger: Terminated due to memory issue


How to reproduce:

App is crashing right after taking picture. Auto-capture should be ON.


Allocations instrument gave me no clue. Memory usage is about 180MB and doesn't have high peaks on working devices. I tried to set prefersBackgroundProcessing to true on Vision requests but it gave no result.


Example project:

h t t p s : / / g i t h u b . c o m / d k a l a c h o v / iPhone8CrashDemo (sorry, this fixes "The message contains invalid characters" error when posting question)

Camera/CameraController.swift - camera

Rectangle Detection/RectangleDetectorForCamera.swift - rect detection code


Thank you,

Dima