Search code examples
iosswiftiphonegraphicscoreml

Memory leaks when using methods of Apple PoseNet model


I am using code from example «Detecting Human Body Poses in an Image» (source is available by Download in link). When I launching this code on my iPhone 7+ there is major increase of usage memory, after my device heats up and application will crashed. In my code I am using predict method of Posenet class. After debugging I realized problem appears when there is calling model, but I don’t know how to fix it.

func predict(_ image: CGImage) {
    DispatchQueue.global(qos: .userInitiated).async {
        let input = PoseNetInput(image: image, size: self.modelInputSize)
        //Problem is below
        guard let prediction = try? self.poseNetMLModel.prediction(from: input) else {
            return
        }
        //Problem is above
        let poseNetOutput = PoseNetOutput(prediction: prediction,
                                          modelInputSize: self.modelInputSize,
                                          modelOutputStride: self.outputStride)

        DispatchQueue.main.async {
            self.delegate?.poseNet(self, didPredict: poseNetOutput)
        }
    }
}

Method is called from captureOutput. What is the problem? How to fix it?

P.S. This is memory usage after 1,5 minutes starting app. When memory usage is reaching 600 MGB application is crashed. Memory usage after 1,5 minutes starting app

A lot of memory leaks and CVObject memory usage. But I don't know how to fix it. CVObject memory usage

enter image description here


Solution

  • It was problem in iOS version. It had been iOS 13.0.1 and when I updated it up to 13.5.1 problem was solved.