

A
Memory management is a core part of building stable iOS applications. Interviewers ask this to assess whether you understand object lifecycles, performance trade-offs, and common causes of leaks or crashes.
Explain how memory is managed in iOS applications. In your answer, address:
The interviewer expects a practical engineering explanation rather than compiler internals. Cover the object ownership model, common pitfalls in UIKit/Swift code, and the tools and coding patterns you would use to keep memory usage under control.
ARC is the ownership system used by Swift and Objective-C to manage the lifetime of class instances. It inserts retain and release operations at compile time and deallocates an object when its strong reference count reaches zero.
class User {
let name: String
init(name: String) { self.name = name }
}
Only reference types such as classes participate in ARC. Value types like structs and enums are copied by value and do not create retain cycles in the same way, which is one reason Swift encourages value semantics where appropriate.
struct Point {
var x: Int
var y: Int
}
A retain cycle happens when two objects hold strong references to each other, preventing either from being deallocated. This commonly occurs with delegates, closures capturing self, parent-child object graphs, and timers.
class A { var b: B? }
class B { var a: A? }
// If both are strong, neither is released.
A weak reference does not increase the reference count and becomes nil automatically when the referenced object is deallocated. An unowned reference also does not retain, but it assumes the object will still exist when accessed, so using it incorrectly can crash the app.
weak var delegate: SomeDelegate?
unowned let owner: Owner
Xcode provides Instruments, the Memory Graph Debugger, and leak analysis tools to find leaks, cycles, and unexpected object retention. These tools help confirm whether objects are deallocated and identify where references are being held.