Memory Management in iOS ARC Runtime
How to spot retain cycles in iOS before jetsam kills your app.

Memory management in the iOS ARC runtime gives engineers predictable object lifetimes, but it does not design ownership for them. Engineers gain from knowing where strong references stay alive, choosing weak and unowned references with care, and measuring the footprint that results. That discipline becomes more consequential when SwiftUI moves ownership out of the view layer and on-device AI consumes a large share of available memory.
Why ARC behaves differently from garbage collection, and why that difference matters on a phone
ARC inserts retain and release calls at compile time, directly into the binary. Those instructions update reference counts as the code runs, and deallocation happens synchronously when an object’s count reaches zero. There is no future sweep to await. By contrast, garbage collection keeps unused objects until a collection cycle reclaims them, which can occupy memory longer and introduce unpredictable pauses. ARC’s compile-time machinery therefore gives engineers a way to reason about runtime lifetimes rather than merely hope that unused memory will soon be reclaimed.
That predictability has particular value on a phone. A phone has far less RAM than a desktop, and iOS can terminate a process that exceeds its memory budget. A didReceiveMemoryWarning notification may precede termination, but warnings are best-effort and are not guaranteed. A stable footprint is therefore a correctness requirement.
The boundary of this mechanism is equally important. ARC manages reference types, including classes, closures, and actors, while structs and enums are value types. Value types are copied and are typically stack-allocated, although they can reside on the heap in some circumstances. They can also contain reference-type properties, so copying a value can still involve reference-counting work. Choosing a struct does not, by itself, remove every ownership concern from the data it contains.
What the compiler inserts and what that leaves the engineer responsible for
The compiler handles reference-count bookkeeping, but it cannot resolve ownership that forms a strong cycle. If object A strongly references B and B strongly references A, removing the local variables that originally referred to them does not bring either count to zero. Each object keeps the other alive indefinitely. Apple’s ARC documentation states that ARC cannot resolve strong reference cycles on its own. The engineer must change the ownership relationship.
Strong references are the default and increment the reference count, making them appropriate when an object owns another object. Weak references do not increment it and become nil when their target is deallocated, so they must be optional. Unowned references also leave the count unchanged, but a non-optional unowned reference assumes that its target is still alive. Access after that target is deallocated crashes the application. The practical rule is to use weak when the target might disappear and unowned only when its lifetime is guaranteed to outlast the referencing object.
That distinction is most useful when applied to recognizable code shapes. A closure creates a cycle when it strongly captures self and that same object holds the closure. A capture list with [weak self] or [unowned self] breaks that strong connection, and the choice must follow the lifetime guarantee. Swift 5.8+ allows implicit self inside a weak capture after self has been unwrapped with a guard-let, so fewer member-access annotations are needed and the ownership rule stays the same.
A view controller may own an object and set itself as that object’s delegate. If the delegate property is strong, both objects retain each other. Declaring the delegate property as weak var removes that return ownership edge. The same distinction applies when a child needs to refer to its parent without keeping the parent alive.
Observers make the return edge less obvious. An owner can hold an observer whose callback strongly captures that owner, completing the same cycle through an additional relationship. Combine’s sink and NotificationCenter’s block-based API are common places to find this pattern and use a capture list that breaks the cycle. The problem extends beyond these canonical leaks, since passing copied structs to sorting comparison closures can also involve ARC activity and allocation that are difficult to trace even in disassembly.
How SwiftUI and MVVM concentrate ARC complexity in ways UIKit did not
SwiftUI removes one source of ownership complexity because its views are structs rather than the class instances used in UIKit’s view hierarchy. The view values’ freedom from reference-counted cycles is a genuine architectural improvement. It does not extend automatically to the reference-type objects attached to those views, including view models, Combine publishers, and the objects captured by async Task closures.
A @StateObject view model can capture itself inside a Combine sink or an async Task closure and participate in the same retention pattern as a UIKit view controller. The enclosing UI representation and the retained object have different lifetime rules. In an MVVM design, that difference concentrates the need for careful capture choices in the view model.
@ObservedObject exposes the other side of that boundary because it does not own its view model. Ownership must exist elsewhere in the architecture. Misplacing it can produce premature deallocation or indefinite retention, depending on which relationships remain. The architecture must therefore establish which object is responsible for keeping the model alive and when that responsibility ends.
MVVM-C makes that responsibility explicit at the navigation level. Coordinators should hold strong references to their child coordinators, with ownership scoped so that ending a navigation flow allows ARC to reclaim the flow. Strong ownership is necessary in the right direction. It becomes a leak when a return relationship prevents the owning structure from being released. Clean boundaries reduce the opportunities for cycles, while mixed responsibilities make the lifetime of a flow harder to reason about.
How to find cycles before users do: Instruments and the Memory Graph Debugger
Instruments shows allocated objects over time and flags unreachable allocated memory, making it suited to detecting growth under real usage patterns and measuring whether a fix changes that behavior.
The Memory Graph Debugger supplies the relationship view during a live debug session. Its graph shows objects and the references between them, making a retain cycle visible as a loop. That is the more direct tool when the question is which object holds another object alive. The practical workflow is to use Instruments to establish the leak and its magnitude, then use the graph to locate the reference responsible. Returning to Instruments provides a way to assess the fix under the usage pattern that exposed the growth.
This workflow belongs before release. When Memory P95 nears a jetsam-risk threshold in production, it signals that ownership defects now put the process at risk of termination. Because memory warnings are not guaranteed, the absence of a warning does not demonstrate sufficient headroom. Profiling must establish the growth pattern before the kernel ends the process. The tools connect a visible symptom in memory use to a specific relationship that engineering can change.

What on-device LLMs do to iOS memory budgets and how mmap changes the equation
Running a language model on-device needs memory that a call to a cloud API does not. Reading gigabytes of weights from disk, compiling them for the Neural Engine, and managing a KV cache all happen within iOS’s constrained process budget. Correct ARC ownership remains necessary, but it is insufficient. A model that barely fits, or uses roughly half the available budget, leaves much less room for the application around it. Even with no leaks, a loading strategy can have a working set that is too large.
Memory mapping changes that loading strategy. With llama.cpp, model weights can be mapped rather than loaded into the heap, allowing the kernel to page weights in and out as needed. This can make the measured working set much smaller and help the application keep running under memory pressure. The recommended default on iOS is to use mmap unless there is a specific reason not to. This is a different decision from choosing a capture list because it concerns how model data occupies memory.
That distinction separates on-device engineering from API integration. The memory assessment must still include the KV cache and the rest of the application. A smaller measured working set is useful evidence, but it does not remove the need to measure the complete feature under use.
Apple’s Core AI framework, introduced with iOS 27, addresses model execution at the platform level through a modern, memory-safe Swift API built for Apple Silicon. Apple’s framework documentation describes fine-grained control over inference memory, zero-copy data paths, and stateful execution. These capabilities reduce the amount of manual memory coordination required for on-device models. Attribution also changes the reported process footprint. Apple’s iOS 27 release notes state that attribution of Neural Engine memory usage has moved from the system to the app process.
Swift 6 introduced borrowing for read-only access without incrementing a reference count and consuming for moving a value without copying it. These tools cut out reference-count traffic and copies that code does not need on paths where speed matters. They augment ARC. Deterministic deallocation remains the foundation, while explicit ownership narrows the work needed to preserve safe lifetimes.
Apple’s WWDC 2026 Swift session extends that direction into ordinary code. The new Iterable protocol lets for loops borrow elements rather than copy them without changing the loop’s syntax. The borrow and mutate accessors also augment computed-property access to avoid copies of large values. These additions are especially relevant to AI inference, large data pipelines, and animation-critical paths.
Treating memory footprint as a measurable product outcome, not a technical detail
Crash rates, app store ratings, and subscription retention make the consequences visible beyond the implementation. A retained view model and an oversized inference working set have different causes, but both consume the budget on which reliable execution depends. Their product relevance is not an implementation detail. Engineering reports become more useful when they connect a measured change in footprint from a leak fix to the application’s stability.
Memory footprint therefore belongs on the same dashboard as DAU growth and in-app purchase revenue. Placing it there treats performance as a product result rather than an isolated maintenance task. That does not justify claiming revenue gains from a memory fix without evidence. The dashboard gives teams a shared way to judge technical improvements against results the business already measures. Product and executive stakeholders can then judge the work by its reported results as well as by how engineers describe the code.
The actionable posture is to profile, measure, and report. Profiling reveals where the application retains memory, measurement establishes the size and direction of the change, and reporting connects that result to shipped performance. ARC supplies predictable mechanics, while engineers supply ownership intent and evidence that the resulting footprint fits the product’s constraints. The standard is an application whose memory behavior has been understood before release and reported as a measurable outcome.


