When does an associated object get released?

前端 未结 4 1889
无人及你
无人及你 2020-11-27 12:32

I\'m attaching object B via associative reference to object A. Object B observes some properties of object A through KVO.

The problem is that object B seems to be d

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 12:37

    objc_getAssociatedObject() for an OBJC_ASSOCIATION_RETAIN association returns an autoreleased object. Might you be calling it earlier in the same runloop cycle / autorelease pool scope as object A is deallocated? (You can probably test this quickly by changing the association to NONATOMIC).

提交回复
热议问题