gpt4 book ai didi

objective-c - Objective-C 运行时是否会为用户释放保留的关联引用?

转载 作者:太空狗 更新时间:2023-10-30 03:35:52 26 4
gpt4 key购买 nike

当像这样的一些代码时:

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

我需要调用相关的吗

objc_setAssociatedObject (
obj,
&key,
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.

关于objective-c - Objective-C 运行时是否会为用户释放保留的关联引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6122600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com