iOS

Memory Management & ARC

ARC, strong/weak/unowned, retain cycles, capture lists, memory leaks, profiling

22 câu hỏi phỏng vấn·
Senior
1

What is ARC (Automatic Reference Counting) in iOS?

Câu trả lời

ARC is an automatic memory management mechanism that counts references to objects. The compiler automatically inserts retain and release calls, eliminating manual memory management. When the reference count reaches zero, the object is deallocated. ARC significantly simplifies iOS programming by preventing common memory leaks.

2

What is a strong reference in ARC?

Câu trả lời

A strong reference increments the reference counter of the referenced object. By default, all variables are strong references. The object remains in memory as long as at least one strong reference points to it. Using too many strong references can create retain cycles preventing deallocation.

3

What is a retain cycle?

Câu trả lời

A retain cycle occurs when two or more objects hold strong references to each other. Neither can be deallocated because each prevents the other's reference count from reaching zero. This creates a memory leak. Retain cycles are prevented by using weak or unowned references in circular relationships.

4

What is the role of deinit in ARC memory management?

5

What is the difference between weak and unowned references?

+19 câu hỏi phỏng vấn

Nắm vững iOS cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí