NSMenuItem -setTarget:它是否保留目标?

发布于 2024-09-12 04:55:44 字数 142 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

羅雙樹 2024-09-19 04:55:44

我不相信确实如此。通常,目标操作方法和委托属性不会保留其设置的内容,因为它们不“拥有”其目标。

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.

怪我入戏太深 2024-09-19 04:55:44

只需查看标头:

@property (nullable, weak) id target;

或者在 Swift 中:

weak var target: AnyObject? { get set }

这里我们看到 targetweak,这意味着 它无法控制目标的生命周期。用技术术语来说,它既不增加也不减少引用计数。一旦您的目标因任何原因被释放,NSMenuItem也会丢失它。

Simply look at the header:

@property (nullable, weak) id target;

or in Swift:

weak var target: AnyObject? { get set }

Here we see that target is weak, 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文