Browse Questions
- Result<Success, Failure> is an enum with .success and .failure cases.
- SSL pinning validates that the server's certificate matches a known copy embedded in the app, preventing man-in-the-middle attacks even with valid certificates.
- A memory leak is memory that is allocated but never freed — usually from retain cycles.
- View controller containment is the API for embedding one view controller inside another so the child keeps its own lifecycle.
Answer: A memory leak is memory that is allocated but never freed — usually from retain cycles. Over time it causes the app to use more and more memory and eventually crash.
How to find leaks with Instruments:
Xcode → Product → Profile(orCmd+I)- Choose Leaks template
- Use the app to trigger the suspected leak
- Instruments marks leaked objects in red
- Click a leak to see the allocation stack trace
Finding retain cycles with Memory Graph:
- Run the app in Xcode
- Click the Memory Graph button (3 circles icon in debug bar)
- Look for objects that shouldn't exist — e.g.
MyViewControllerthat was dismissed - Click the object to see what's retaining it
Code Example — common leak:
// ❌ Retain cycle — both objects keep each other alive
class ViewController: UIViewController {
var timer: Timer?
override func viewDidLoad() {
// Timer retains self strongly
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
self.update() // strong capture
}
}
// timer never invalidated → ViewController never deallocated
}
// ✅ Fix
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
self?.update()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
timer?.invalidate()
}