• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Objective-C 运行时版本会为用户保留关联引用吗?

用户头像
it1352
帮助1

问题说明

当一些像这样的代码时:

When some codes like this:

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

我需要打电话给相关人员吗

Do I need to call related

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

释放保留值?Objective-C 运行时会自动释放 dealloc 或其他地方的关联引用吗?

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

正确答案

#1

当父对象被释放时,关联的对象将被释放.请参阅文档 这里,特别是这个例子:

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

在第 1 点,字符串 overview 仍然有效,因为 OBJC_ASSOCIATION_RETAIN 策略指定数组保留关联对象.然而,当数组被释放时(在第 2 点),overview 被释放,因此在这种情况下也被释放.

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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfekih
系列文章
更多 icon
同类精品
更多 icon
继续加载