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

Why delegate is...

Câu trả lời

Here is an explanation for why delegates are never retained in Objective-C:

Delegate Pattern in Objective-C

In Objective-C, the delegate pattern is a common design pattern used to implement one-to-one communication between objects. A delegate is an object that acts on behalf of another object, handling tasks and responding to messages on its behalf.

Weak References and Delegates

When an object sets another object as its delegate, it typically uses a weak reference to the delegate. This means that the delegate is not retained or owned by the object that sets it. The reason for this is to avoid a strong reference cycle, which can lead to memory leaks.

Avoiding Strong Reference Cycles

If an object retained its delegate, and the delegate also had a strong reference back to the object, it would create a strong reference cycle. This means that both objects would hold strong references to each other, preventing them from being deallocated even when no other part ...

senior

senior

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

expert

What is Dynamic Dispatch and how does it work in Objective-C?

middle

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

expert

Explain the use case when ARC won't help you to release memory (but GC will)

Bình luận

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

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