Objective-C运行时版本是否会保留用户的关联引用?

前端之家收集整理的这篇文章主要介绍了Objective-C运行时版本是否会保留用户的关联引用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当一些代码像这样:
objc_setAssociatedObject (
  obj,&key,val,OBJC_ASSOCIATION_RETAIN
);

我需要打电话给相关的

objc_setAssociatedObject (
  obj,nil,OBJC_ASSOCIATION_RETAIN
);

释放保留值? Objective-C运行时是否自动释放dealloc或某处的关联引用?

解决方法

取消分配父对象时将释放关联对象.请参阅文档 here,特别是此示例:

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.

猜你在找的C&C++相关文章