NSMenuItem -setTarget:它是否保留目标?
NSMenuItem -setTarget:它是否保留目标,或者应该显式保留它?
我见过关于此的相互矛盾的文档。我知道 NSIn Vocation 中的保留参数,但我不确定这是否适用于 NSMenuItem,因为它不是从 NSInitation 继承的。
NSMenuItem -setTarget: Does it retain the target, or should one explicitly retain it?
I've seen conflicting docs on this. I know of retainArguments in NSInvocation, but I'm not sure this applies to NSMenuItem as it doesn't inherit from NSInvocation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信确实如此。通常,目标操作方法和委托属性不会保留其设置的内容,因为它们不“拥有”其目标。
I don't believe it does. Usually target-action methods and delegate properties don't retain what they're set to, as they don't “own” their target.
只需查看标头:
或者在 Swift 中:
这里我们看到
target
是weak
,这意味着 它无法控制目标的生命周期。用技术术语来说,它既不增加也不减少引用计数。一旦您的目标因任何原因被释放,NSMenuItem
也会丢失它。Simply look at the header:
or in Swift:
Here we see that
target
isweak
, meaning that it doesn't have control over the target's lifetime. In technical terms, it neither increments nor decrements the reference count. Once your target is deallocated for any reason,NSMenuItem
loses it too.