Skip to content

Conversation

@DavidBertet
Copy link
Contributor

Issue

  • Self is accessed within AVCaptureEventInteraction closure
  • The AVCaptureEventInteraction is stored in eventInteraction class variable
  • This creates a retain cycle

let interaction = AVCaptureEventInteraction { event in
// Capture a photo on "press up" of a hardware button.
if event.phase == .began {
self.onCaptureButtonPressIn?(nil)
} else if event.phase == .ended {
self.onCaptureButtonPressOut?(nil)
}
}

Solution

Use [weak self] to break the cycle

How did you test this change?

  • Launch App
  • Open Camera 3 times

Before

  • Observe leak, 3 instances of CKCameraView because of the closure
    before

After

  • No leak, closure doesn't retain anything
    after

Self is accessed within AVCaptureEventInteraction closure, which is stored in eventInteraction class variable, creating a retain cycle
Use [weak self] to break the cycle
teslamotors@21f7601#diff-5011dc3d3aefd7b67661ffa11130868519526e31f62f630ebf6ddc2d7f714e09R128-R135
@scarlac scarlac merged commit a4fef76 into teslamotors:master Aug 26, 2025
4 checks passed
@scarlac
Copy link
Collaborator

scarlac commented Aug 26, 2025

🙏 Thanks @DavidBertet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants