From cee93fdff1694cd646708ec6ae93fa2e5c2aa8f3 Mon Sep 17 00:00:00 2001 From: David Bertet Date: Thu, 17 Jul 2025 23:42:22 -0700 Subject: [PATCH] Fix memory leak introduced in 21f7601 Self is accessed within AVCaptureEventInteraction closure, which is stored in eventInteraction class variable, creating a retain cycle Use [weak self] to break the cycle https://github.com/teslamotors/react-native-camera-kit/commit/21f760117b8865cb1865001cf14a728087162e8d#diff-5011dc3d3aefd7b67661ffa11130868519526e31f62f630ebf6ddc2d7f714e09R128-R135 --- ios/ReactNativeCameraKit/CameraView.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ios/ReactNativeCameraKit/CameraView.swift b/ios/ReactNativeCameraKit/CameraView.swift index ad161e5ab..1985556d4 100644 --- a/ios/ReactNativeCameraKit/CameraView.swift +++ b/ios/ReactNativeCameraKit/CameraView.swift @@ -134,12 +134,12 @@ public class CameraView: UIView { #if !targetEnvironment(macCatalyst) // Create a new capture event interaction with a handler that captures a photo. if #available(iOS 17.2, *) { - let interaction = AVCaptureEventInteraction { event in + let interaction = AVCaptureEventInteraction { [weak self] event in // Capture a photo on "press up" of a hardware button. if event.phase == .began { - self.onCaptureButtonPressIn?(nil) + self?.onCaptureButtonPressIn?(nil) } else if event.phase == .ended { - self.onCaptureButtonPressOut?(nil) + self?.onCaptureButtonPressOut?(nil) } } // Add the interaction to the view controller's view.