Memory and ARC interview questions
48 questions from real iOS interviews. Topics: ARC, retain cycles, weak and unowned, memory layout, leak debugging.
- Memory and ARCShort answer카카오
ARC basics
What is ARC, and why do we need it?
#arc #reference-counting #retain #release
- Memory and ARCMultiple choice
strong / weak / unowned
Which of the following statements about weak references are correct? Select all that apply.
#weak #unowned #strong #optional
- Memory and ARCMultiple choice
Stack and heap
Which statement about the stack and the heap is correct?
#stack #heap #allocation #struct
- Memory and ARCShort answer
Impact of memory leaks
What is a memory leak?
#leak #memory-warning #jetsam #user-impact
- Memory and ARCMultiple choice
When deinit runs
What does this code print? …
#deinit #reference-count #lifetime
- Memory and ARCShort answer지마켓글로벌
weak vs strong
Can you explain the difference between weak and strong?
#weak #strong #arc #reference-counting
- Memory and ARCShort answerTeladoc Healthinterview report
ARC ownership and deallocation timing
In an iOS app written in Swift, how does ARC manage the lifetime of a class instance?
#arc #ownership #deinit #strong-reference
- Memory and ARCShort answerDeloitteinterview report
unowned access risk
A coworker wants to declare every delegate unowned instead of weak because unwrapping optionals is a hassle. Why isn't an unowned reference optional?
#unowned #weak #runtime-trap #arc
- Memory and ARCShort answer
Diagnosing reference cycles
A view controller doesn't seem to leave memory after you close its screen. How would you confirm there's actually a reference cycle?
#retain-cycle #leak #memory-graph #deinit
- Memory and ARCMultiple choice
Closure capture and leaks
Which of these two snippets creates a reference cycle? …
#closure #capture #weak-self #retain-cycle
- Memory and ARCShort answer
Choosing weak vs unowned
When would you use unowned instead of weak?
#weak #unowned #lifetime #crash
- Memory and ARCShort answer
Delegates and weak references
You try to declare weak var delegate: MyDelegate? and the compiler rejects it. Why, and how do you fix it?
#delegate #weak #anyobject #protocol
- Memory and ARCMultiple choice
When cycles happen
Which of the following (with no extra measures) create a reference cycle or a permanent leak? Select all that apply.
#retain-cycle #timer #notification #closure
- Memory and ARCShort answer
Retain cycle vs memory leak
Are "reference cycle" and "memory leak" the same thing?
#retain-cycle #leak #abandoned-memory
- Memory and ARCMultiple choice
Capture lists
What does this code print? …
#closure #capture-list #value-capture
- Memory and ARCShort answer
MRC and autorelease
Before ARC, Objective-C code called retain, release, and autorelease directly. What did each one do, and what did ARC change?
#mrc #retain #release #autorelease
- Memory and ARCMultiple choice
Using autoreleasepool
This code spikes memory and gets the app killed. What's the most appropriate fix? …
#autoreleasepool #peak-memory #loop #uiimage
- Memory and ARCShort answer
Shallow vs deep copy
In struct Order { var items: [Item]; let customer: Customer }, Item is a struct and Customer is a class. After var copy = order, what happens to the original i…
#shallow-copy #deep-copy #nscopying #struct
- Memory and ARCMultiple choice
Objective-C property attributes
In Objective-C, why do you use copy instead of strong for an NSString property, as in @property (nonatomic, copy) NSString *name;? Pick the best reason.
#objective-c #copy #strong #nsstring
- Memory and ARCMultiple choice하이퍼커넥트
Spotting leak patterns
Which of the following snippets keep a ViewController from being deallocated after it leaves the screen (that is, cause a leak)? Select all that apply. Each sn…
#leak #timer #notificationcenter #closure
- Memory and ARCMultiple choiceZomato
Rules of ARC and weak
Which of the following statements about ARC and weak are correct? Select all that apply.
#arc #weak #compile-time #enum
- Memory and ARCShort answerCRED
Proving a leak fix
Think of a memory leak you actually ran into. How did you find it, how did you pin down the cause, and how did you prove it was fixed?
#leak #memory-graph #instruments #regression-test
- Memory and ARCShort answerDoorDashinterview report
Retain cycle example
Give me a concrete code example that creates a retain cycle, and fix it.
#retain-cycle #closure #singleton #weak-self
- Memory and ARCShort answerSalesforceinterview report
Closure capture cycles
A messaging app's ViewModel keeps a completion closure in a property for a long time, and inside it updates self.messages. What reference graph creates the ret…
#closures #retain-cycle #weak-self #arc
- Memory and ARCShort answerXiaomi
Deep copy, shallow copy, and COW
In Swift you assign a large array to another variable with var b = a and then modify only b. Is what happens a shallow copy or a deep copy? Explain it together…
#copy #cow #value-semantics #memory
- Memory and ARCShort answerZillowinterview report
Finding who holds a view controller
You closed a UIKit screen but its ViewController stays in memory. Without just trusting the deinit log, how would you find who's holding it?
#memory-graph #viewcontroller #timer #observer
- Memory and ARCShort answer
Core Foundation and ARC
When you handle a Core Foundation object returned by a C API like SecItemCopyMatching or CGImageSource in Swift, when do you use Unmanaged, takeRetainedValue()…
#core-foundation #unmanaged #toll-free-bridging #takeretainedvalue
- Memory and ARCShort answer
How closure capture works
What actually happens in memory when a closure captures an outside variable? Using the output of the code below, explain the difference between using a capture…
#closure #capture #capture-list #box
- Memory and ARCShort answer
iOS memory and Jetsam
Sometimes an app you sent to the background comes back and starts from scratch. Explain this using how iOS manages memory: virtual memory, compression, and Jet…
#virtual-memory #jetsam #memory-warning #background
- Memory and ARCMultiple choice
Class performance and ARC traffic
Which of these actually improve the performance of class-based code (dispatch and ARC cost)? Select all that apply.
#final #private #dispatch #arc-traffic
- Memory and ARCShort answer
unowned crash scenario
This code, which loads an image asynchronously in a UITableView cell, crashes now and then. Under what condition does it crash, and why? …
#unowned #crash #lifetime #closure
- Memory and ARCShort answer
Memory cost of value types
How far is it true that "using a struct means no ARC cost"?
#value-type #cow #arc-traffic #struct
- Memory and ARCMultiple choice
Judging unowned
In which of the following is a [unowned self] capture safe? Select all that apply.
#unowned #weak #closure #lifetime
- Memory and ARCShort answer
Task and self capture
After moving to Swift Concurrency, your team is arguing about whether you always need [weak self] inside Task { }. When is it unnecessary, and in which Tasks i…
#task #swift-concurrency #weak-self #capture
- Memory and ARCShort answer쿠팡
Subscription lifetime
In a live coding session you're handed the following Combine ViewModel. Add a feature that subscribes to the price stream and reflects it in priceText, and exp…
#combine #cancellable #closure #weak-self
- Memory and ARCShort answer네이버웹툰
ARC follow-up drill
Starting from "explain ARC," the follow-ups keep coming. First: who inserts retain and release, and when?
#arc #retain-release #value-type #ownership
- Memory and ARCShort answerPayPal
ARC deallocation steps
From the moment an object's last strong reference goes away until the memory is actually returned, what does ARC do? Walk me through it step by step.
#arc #deinit #weak #unowned
- Memory and ARCShort answerFlipkart
Struct copies and COW buffers
… After s2.a = 9, are the addresses where s1.a and s2.a are stored the same or different, and what about the buffer address of the tags array?
#struct #cow #array #memory-address
- Memory and ARCShort answerMicrosoft
autorelease buildup in loops
A for loop that runs fine on up to 5,000 records crashes after a memory warning above that. Inside the loop you slice and concatenate strings and repeatedly co…
#autoreleasepool #runloop #foundation #bridging
- Memory and ARCMultiple choiceByteDance
atomic properties and increments
In Objective-C you declare @property (atomic) int a; and run self.a = self.a + 1 a combined 10,000 times from several threads. Is a 10,000 at the end? And how …
#objective-c #atomic #thread-safety #race-condition
- Memory and ARCShort answerXiaohongshu
Dangling pointers and Zombie Objects
In what situations does a dangling (wild) pointer, one that touches a deallocated object, arise under ARC?
#dangling-pointer #zombie #exc-bad-access #asan
- Memory and ARCShort answerShopee
ARC vs garbage collection
iOS manages memory with reference counting (ARC). If you had to implement automatic memory management without reference counts, what approach could you take?
#arc #garbage-collection #deterministic #design-rationale
- Memory and ARCShort answerJD.com
Stored closures and self lifetime
A UIKit ViewController keeps an upload completion block in a property, and the block changes one of the ViewController's labels. After the upload finishes the …
#closure #retain-cycle #completion #lifetime
- Memory and ARCShort answer네이버웹툰
Shared references inside value types
A webtoon app's Episode struct has an ImageCache property of class type. If you copy the struct and change the cache on one side, what state is shared with the…
#struct #class #value-semantics #reference
- Memory and ARCShort answer
How weak works at runtime
Why is it true that "weak is slower than strong"? Explain it with the Swift runtime's reference count layout: the inline refcount and the side table.
#weak #side-table #refcount #runtime
- Memory and ARCShort answer
Memory layout
What are MemoryLayout<T>.size, stride, and alignment, and why can the three differ? Use the struct below as your example. …
#memorylayout #size #stride #alignment
- Memory and ARCShort answer
Advanced leak hunting
Both the Leaks instrument and Memory Graph are clean, yet every time you go back and forth to a certain screen, memory on a real device grows by 30MB. What cou…
#leak #instruments #malloc-stack #vm-tracker
- Memory and ARCMultiple choice
Ownership modifiers and ~Copyable
Which statement about Swift 5.9's ownership features (borrowing/consuming parameters, ~Copyable types) is correct?
#ownership #borrowing #consuming #noncopyable