mediumConceptScenarioMidSenior
How do retain cycles happen in Swift closures and delegates, and how would you find one in an app that is slowly leaking memory?
4 min readUpdated 2026-08-15
Answer
Short answer
A closure or delegate reference that captures its owner strongly, while the owner also holds that closure or delegate strongly, forms a cycle ARC cannot break on its own, and the fix is weak or unowned capture chosen by lifetime, not by habit.
Was this answer helpful?
Likely follow-ups
- Why does delegate almost always need to be declared weak var even when the protocol is a class-only protocol?
- What is the difference between how a retain cycle presents in the Memory Graph Debugger versus a genuine one-off leak?
- Why is unowned dangerous specifically when the closure can outlive the object it captures?
- How does a capture list interact with a closure that is stored as a property versus one that is passed and executed immediately?
Related questions
- A deep link opens the right screen when the app is in the background and the wrong one when the app was killed. How do you test for that?mediumAlso on ios5 min
- How do you choose which devices to test on, and what will an emulator never tell you?mediumAlso on ios5 min
- Your SwiftUI screen redraws constantly and scrolling stutters - how would you find out why, and what state-management mistake usually causes it?mediumAlso on ios4 min
- Why do low-latency systems preallocate arenas instead of calling the general-purpose allocator on the hot path?hardAlso on memory-management7 min