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

middle

What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?

middle

What is the difference between inheritance and Categories in Objective-C?

middle

What are some limitations and problems you can face with categories?

Bình luận

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

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