yoklainterview sim

Mobile Ios Memory Management Arc Interview Questions

75 verified Mobile Ios Memory Management Arc interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Ios Memory Management ArcDifficulty 1
What does ARC (Automatic Reference Counting) actually count?
  • aHow many strong references currently point to a given class instance
  • bHow many times a function has been called in total
  • cHow many bytes of disk storage an app has used
  • dHow many optional variables are declared in the file
Explanation:ARC tracks the number of strong references to each class instance; when that count reaches zero, the instance is deallocated.
Ios Memory Management ArcDifficulty 1
When does a class instance's deinit run?
  • aImmediately the moment the instance is first created
  • bRight when its strong reference count drops to zero and it's about to be deallocated
  • cOnly when the app is force-quit by the user
  • dEvery time any of its properties changes value
Explanation:deinit is the deinitializer, called exactly once, right before the instance is deallocated because no strong references remain.
Ios Memory Management ArcDifficulty 1
Two class instances, A and B, each hold a strong reference to the other, and nothing outside references either. What is this situation called?
  • aA weak reference chain
  • bA retain cycle (strong reference cycle)
  • cA dangling pointer
  • dA copy-on-write violation
Explanation:When two objects strongly retain each other with no external reference, neither's count ever reaches zero, so ARC can never deallocate them — this is a retain (strong reference) cycle, a form of memory leak.
Ios Memory Management ArcDifficulty 1
What does declaring a property weak var delegate: SomeDelegate? do to ARC's reference count for the referenced object?
  • aIt increases the strong reference count by exactly one, same as a normal reference
  • bIt permanently sets the reference count to zero immediately
  • cIt doubles the reference count for safety
  • dIt does not increase the strong reference count at all
Explanation:A weak reference doesn't contribute to the strong reference count, so holding an object via weak alone won't keep it alive.
Ios Memory Management ArcDifficulty 2
What happens to a weak reference's value when the object it points to is deallocated?
  • aIt keeps pointing to the freed memory location unchanged
  • bIt crashes the app the instant deallocation happens
  • cIt is silently converted into a strong reference to prevent this
  • dIt automatically becomes nil
Explanation:Weak references are automatically set to nil by the runtime once the referenced object is deallocated, which is exactly why weak references must be declared as optional.
Ios Memory Management ArcDifficulty 2
Why must a weak var property always be declared as an Optional type (e.g. weak var x: Foo?, never weak var x: Foo)?
  • aBecause Optional types use less memory than non-optional class references
  • bBecause the reference can become nil at any time when the referenced object is deallocated
  • cBecause the Swift compiler requires all weak keywords to precede an enum type
  • dBecause non-optional weak references would always crash on declaration
Explanation:Since a weak reference can be set to nil automatically at any point in its lifetime, the type system requires it to be Optional so that nil is a representable, valid value.

Test yourself against the 2400-question Mobile bank.

Start interview