当一些代码像这样:
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 theOBJC_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.