iOS Interview Prep 1 — Memory management
The purpose of this interview preparation series is to assist you in quickly refining your interview skills and thoroughly preparing for the typical questions asked during an iOS interview. If you find it useful, please leave a comment or tap the like button.
Overview
Memory management is one of the most frequently asked questions during iOS interview, it’s a huge red flag if you fail to demonstrate a good understanding of the basic concepts such as reference cycle, strong/weak reference. To prepare for all kinds of questions related to memory management, it’s key to understand the foundamental mechanism behind the curtain of ARC.
Interview Questions
- Explain how ARC works in Obj-C/Swift
- What are common situations that can lead to memory leak?
- What are some common scenarios where reference cycle might happen?
- When should you use copy property? How does it help you avoid bugs?
- Can you explain the difference between unowned(unsafe) and weak reference?
Auto Reference Counting
Memory management in iOS application is based on a reference counting model. When you initialize a new object, memory is allocated on the heap and reference count is set to 1. The reference count increases as more objects set strong reference to it.