Câu hỏi phỏng vấn Objective-C
Câu hỏi

Explain the use case when ARC won't he...

Câu trả lời

Here is an explanation of when ARC (Automatic Reference Counting) won't help you release memory, but GC (Garbage Collection) would:

Objective-C and Memory Management

In Objective-C, memory management has evolved over time:

  • Manual Reference Counting (MRC) - Developers manually retain and release objects
  • Garbage Collection (GC) - Automatic memory management, objects are collected when no longer referenced
  • Automatic Reference Counting (ARC) - Compiler inserts retain and release calls automatically

When ARC Doesn't Help

ARC is very helpful for most memory management tasks, but there are a few cases where it falls short:

  1. Circular References

    • If two objects hold strong references to each other, ARC can't break the cycle
    • This results in a memory leak, as the objects are never deallocated
    • GC would automatically detect and break circular references
  2. Objective-C Runtime Calls

    • Calling certain Objective-C runtime functions like `objc_setAssociat...
expert

expert

Gợi ý câu hỏi phỏng vấn

expert

Explain method swizzling. When you would use it?

senior

Explain the difference between interfaces, delegates, and protocols in Objective-C

senior

Why delegate is never retained?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào