Weak Self in Swift Closures and When to Use Unowned
A simple lifetime test tells you when `weak` is safe and `unowned` isn't.

Escape behavior shows which captures need a closer look, ownership shows whether there is a cycle, and crash risk guides the choice of a non-owning reference. The repeatable rule is to use weak when self may disappear before the closure finishes, and reserve unowned for lifetimes whose relationship is guaranteed by the architecture.
How ARC creates retain cycles in closures
ARC releases an object when its strong reference count reaches zero. Closures hold strong references to the objects they capture by default, so using self inside a closure normally keeps that instance alive. That alone does not create a retain cycle. A cycle requires a return path, where self also strongly retains the closure, directly or through other objects. The distinction is between keeping an object alive for some work and making its release impossible through mutual ownership.
A UIViewController with a stored completion handler illustrates the condition. The controller owns the handler, and a handler that strongly captures self owns the controller in return. Neither reference count reaches zero when the owners outside the loop release the controller. Breaking the closure’s strong reference to the controller breaks the loop, while the controller can still own its handler.
This analysis applies to reference types, including classes and actors. Structs cannot form retain cycles with each other, but a struct containing a class reference can participate in a larger ownership chain. The diagnostic questions are whether mutual strong retention exists and whether the closure can outlive the intended lifetime of self.
What escape behavior tells you about closure lifetime
A non-escaping closure runs entirely within the function call that takes it, keeping its capture of self bounded to that call. No defensive capture list is needed for that reason. The useful distinction at the call site is whether the closure can remain available after the receiving function returns.
The @escaping annotation makes that possibility explicit. Completion handlers, callback properties, and Combine subscribers can remain alive after the object that created them has logically finished its work. The practical rule is to inspect whether self also owns the closure, including through a subscription or another object, rather than treating the annotation itself as proof of a leak.
A short DispatchQueue.main.async closure shows why that qualification is necessary. It escapes, but it is not a callback property owned by self, and its execution is normally brief. Adding [weak self] reflexively introduces optional handling without necessarily breaking any cycle. Once an escaping closure does form a cycle, the next question is which non-owning capture can safely break it.
The actual difference between weak and unowned: optionality and crash risk
Both weak and unowned avoid strongly retaining the captured object. Their consequences differ when that object disappears. A [weak self] capture is optional, and ARC sets the reference to nil after deallocation. The familiar guard let self = self else { return } pattern lets the closure stop when its owner is gone. Optional handling is the price of accepting that the lifetimes may diverge.
An [unowned self] capture avoids the optional, but it does not become nil when the object is deallocated. Accessing it afterward causes a runtime crash. There is no graceful fallback in that case. A weak capture that is not needed adds optional handling, while an unowned capture based on a wrong lifetime assumption can crash the app. Those are not equivalent failure modes. Uncertainty therefore favors weak.
Apple’s documented rule reserves unowned for a reference that will never be nil once set during initialization. Its CreditCard and Customer example expresses a structural relationship, where the card cannot exist independently of its customer. Applied to a closure, that requires proof that the captured object remains alive whenever the closure accesses it. Expected timing is not such a proof. Differences in optional handling and reference bookkeeping are negligible for typical consumer iOS workloads compared with the consequences of an incorrect lifetime assumption.
The decision rule: object lifetimes determine which keyword to use

The mental checklist begins with escape behavior and ownership. If the closure does not escape, a capture list is not needed to prevent this cycle. If it escapes, trace the strong references for direct or indirect ownership by self. Then ask whether self can be deallocated before the closure finishes executing.
Where a non-owning capture is needed, use [weak self] if the answer is yes or uncertain. Handle the optional so that work requiring the missing object can stop. Use [unowned self] only when the answer is demonstrably no. A parent-child relationship qualifies only if the child’s lifetime is strictly bounded by the parent’s and the reference cannot become absent after initialization.
The practical test is independent destruction. If the referenced object could reasonably be destroyed while the object running the closure remains alive, the unowned assumption fails. Navigation, dismissal, and asynchronous cancellation often let one of those objects outlive the other in app code. That makes [weak self] the safer production default when a non-owning capture is needed, while unowned makes a claim about lifetimes that the architecture must uphold.
Applying the rule to the patterns that actually appear in SwiftUI and MVVM apps
SwiftUI views are structs, but their ObservableObject ViewModels are classes subject to ARC. The ownership audit therefore follows the ViewModel’s references. Use [weak self] in stored or escaping ViewModel closures that would otherwise retain their owner. Property-wrapper choice needs separate attention. In the navigation leak pattern described here, using @ObservedObject where @StateObject is appropriate accompanies repeated creation of ViewModels that never deallocate, so each pushed screen adds retained memory.
Callbacks such as onNoteSelected and onCreateNote can capture the coordinator while the coordinator owns the child that retains the callback. The loop spans more than two objects. The pattern { [weak self] in self?.pushDetail(...) } breaks the callback’s strong reference to the coordinator. Without that break, the callback and child can still keep the coordinator alive after the navigation flow ends.
Combine makes the same chain particularly clear. An object owns an AnyCancellable, which retains a subscriber and its closure, which can retain the original object. Use [weak self] in sink to break the return path. By contrast, assign(to:on:) can retain its target and create a cycle when that target also owns the subscription. For a ViewModel’s @Published property, assign(to:) avoids that explicit target capture. Cancellation remains a separate mechanism from weak capture, as a subscription stored on self cancels when its AnyCancellable is released during deallocation.
Supabase real-time callbacks have an equally clear lifetime boundary. A channel can remain active beyond a TaskViewModel’s intended scope, so a database event may arrive after the screen’s owner should have disappeared. Weak capture accommodates that delayed delivery. The callback pattern uses [weak self] followed by guard let self before dispatching to main. The guard lets the callback use the ViewModel while it still exists, without letting the channel own it for good.
Apps that connect to devices run into similar problems with NotificationCenter and block-based timers while listening for Bluetooth state, location, or CAN-bus data. The observer-retention changes in iOS 9+ do not make strongly capturing observer closures immune to cycles. Use [weak self] in those closures and remove observers in deinit. Execution and ownership require separate checks here. Calling stop() in a timer-owning component may stop its behavior without breaking the closure’s strong ownership loop, so a quiet timer is not proof that its memory has been released.
Where Swift Concurrency changes the calculus — and where it doesn't
Swift Concurrency changes how work is written, and captured references still keep objects alive. A short-lived Task performing bounded work generally releases its closure when it completes, allowing the captured object to be released as well. A task consuming an ongoing stream has a different lifetime and needs a different assessment.
A weak capture followed immediately by guard let self else { return } can obscure that distinction. A task normally starts soon after creation, when self is still alive, and the guard establishes a strong reference for the task’s body. The capture is then effectively strong for that duration. A narrow pre-execution window still exists in which self could disappear, so the patterns are not identical. Nevertheless, putting the guard at the start of a long-lived task does not preserve weak ownership throughout its work.
An AsyncStream of push notifications, Bluetooth events, or LLM tokens can continue publishing long after a screen is dismissed. Such tasks resemble ongoing Combine subscriptions. The LLM token-streaming callback sketch expresses the relevant boundary as [weak self] token in guard let self else { return }; self.messages[assistantIndex].text += token. Here, llm.generate takes the weak callback so that delivering tokens does not keep the ViewModel alive for good. The guard applies to an individual callback invocation rather than establishing ownership across the entire generation task.
Agentic LLM features make these boundaries especially visible. The ownership contract passes through a Core ML model, a Swift 6 actor, a back-pressured AsyncStream, and a @MainActor SwiftUI view. Each boundary needs its own lifetime reasoning. Weak capture does not itself stop generation, just as it does not itself cancel a Combine subscription. The cancellation pattern is to store the task handle as a property and cancel it in deinit, while avoiding a long-lived strong capture that would prevent deinit from being reached.
Tooling and team practices for catching leaks before they ship
Xcode’s Memory Graph Debugger makes the ownership argument inspectable. In the navigation pattern described earlier, a growing population of BigViewModel instances exposes retention that a property-wrapper declaration alone may not reveal. The graph shows the reference relationships behind those instances.
During development, instrument deinit with a print or logging call for ViewModels and coordinators expected to disappear after navigation. A missing message is a reason to inspect retention, particularly after bounded asynchronous work has finished. Then examine the surviving ownership path in the graph. The corresponding code-review rule is that every escaping closure referencing self without a capture list requires discussion. The reviewer’s job is to establish whether a cycle or lifetime hazard warrants inserting [weak self].
SE-0269 permits implicit self in escaping closures when self is explicitly captured or is a value type. It cuts down on syntax without proving that ownership is safe. A closure that compiles without repeated self expressions still needs the same check of its lifetimes, and whether an explicit capture list is correct still depends on how the surrounding code is built.
At team scale, navigation, dismissal, and async cancellation make a shared capture policy especially valuable. Phantomstory Demo, the portfolio of a senior iOS engineer who led a team of 12+ engineers on a flagship consumer app, reflects that production setting, where defaulting to [weak self] for non-owning captures is the safer pattern. Distributed teams benefit from recording when weak, unowned, or neither is appropriate in an engineering guide. That policy reduces per-review ambiguity as module ownership changes. A useful engineering standard is simple enough to write down and precise enough to test against actual object lifetimes.


