开发者

Will Objective-C runtime release retained associative references for user?

开发者 https://www.devze.com 2023-03-08 01:45 出处:网络
When some codes like this: objc_setAssociatedObj开发者_高级运维ect ( obj, &key, val, OBJC_ASSOCIATION_RETAIN

When some codes like this:

objc_setAssociatedObj开发者_高级运维ect (
  obj,
  &key,
  val,
  OBJC_ASSOCIATION_RETAIN
);

Do I need to call related

objc_setAssociatedObject (
  obj,
  &key,
  nil,
  OBJC_ASSOCIATION_RETAIN
);

to release the retained value? Does Objective-C runtime auto release the associative references in dealloc or somewhere?


Associated objects will be released when the parent object is deallocated. See the documentation here, specifically this example:

At point 1, the string overview is still valid because the OBJC_ASSOCIATION_RETAIN policy specifies that the array retains the associated object. When the array is deallocated, however (at point 2), overview is released and so in this case also deallocated.

0

精彩评论

暂无评论...
验证码 换一张
取 消