NSPasteboard 是否保留所有者对象?
您可以像这样调用 NSPasteboard
:
[pboard declareTypes:types owner:self];
这意味着粘贴板稍后会要求所有者根据需要提供类型的数据。然而,我无法从文档中找到(也许我错过了一些明显的东西),是否保留 owner
。
在实践中,让我担心的是,如果所有者是弱引用,它可能会被释放,如果粘贴板尝试向其请求数据,则会导致崩溃。
注意:我可能应该澄清一下,我对此更感兴趣,因为它有助于追踪错误,而不是让我的应用程序依赖它。但我确实也希望文档得到澄清。
You can call NSPasteboard
like this:
[pboard declareTypes:types owner:self];
Which means that the pasteboard will later ask the owner to supply data for a type as needed. However, what I can't find from the docs (and maybe I've missed something bleeding obvious), is whether or not owner
is retained.
In practice what's worrying me is if the owner is a weak reference, it could be deallocated, causing a crash if the pasteboard then tries to request data from it.
Note: I should probably clarify that I'm interested in this more as an aid to tracking down a bug, than making my app rely on it. But I do also want the docs clarified.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档:
翻译:粘贴板可能会也可能不会保留所有者。是否确实如此是您不应该依赖的实现细节。只要所有者仍担任所有者,您就有责任保留所有者。
文档所说的“保持有效”实际上是指您可能懒惰提供的代理内容。即,如果用户要复制某些内容,您不希望当用户进行进一步编辑并打算稍后粘贴时,所有者对复制内容的表示会发生变化。
该文档没有提及所有者的保留/释放策略(也没有任何类型的一揽子规则声明)。应该澄清(rdar://8966209 提交)。事实上,对保留/释放行为做出假设是危险的。
The docs:
Translation: The pasteboard may or may not retain the owner. Whether it does is an implementation detail that you should not rely upon. It is your responsibility to retain the owner for as long as it acts as an owner.
What the docs are saying about "remain valid" actually refers to the proxied contents that you might lazily provide. I.e. if the user were to copy something, you wouldn't want the owner's representation of what was copied to change as the user makes further edits with an intention of pasting sometime later.
The documentation says nothing about the retain/release policy of the owner (nor is there any kind of blanket rule statement). It should be clarified (rdar://8966209 filed). As it is, making an assumption about the retain/release behavior is dangerous.