A memory leak with VNDetectHumanHandPoseRequest

I have noticed that the memory usage of my MacOS app increases about 84MB when I use VNDetectHumanHandPoseRequest, and this extra memory usage remains even after I release all associated objects.

I was able to create a small sample code, which reproduces this behavior.

https://github.com/snakajima/HandPose/tree/main

Code Block
    @IBAction func toggleGesture(_ sender:NSMenuItem) {
        gestureEnabled = !gestureEnabled
        sender.state = gestureEnabled ? .on : .off
        if gestureEnabled {
            handPoseRequest = VNDetectHumanHandPoseRequest()
        } else {
            handPoseRequest = nil
        }
    }
public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
        guard let request = handPoseRequest else {
            return
        }
        let handler = VNImageRequestHandler(cmSampleBuffer: sampleBuffer, orientation: .up, options: [:])
        do {
            try handler.perform([request])
            let results = request.results
            if let count = results?.count, count > 0 {
                print("results.count", count)
            }
        } catch {
            print("Vision Error", error.localizedDescription)
        }
    }


  • Did you solve the issue? I have the same problem with VNSequenceRequestHandler...

Add a Comment