使用 NSString 变量设置 NSTextView 的文本,考虑引用计数
我的 .m 文件中的函数中有以下代码:
desc = [我的executeFunction]; // desc 由executeFunction 返回
数据 = [desc objectAtIndex:0]; // 数据在.h文件中声明
data2 = [desc objectAtIndex:1];
[myTextField setString:数据]; // myTextField 连接到 IB 中的 NSTextView
[myTextField setString:data2];
我应该如何写第四行和第五行?如何/在哪里发布数据和数据2?
I have the following code in a function in my .m file:
desc = [my executeFunction]; // desc is returned by executeFunction
data = [desc objectAtIndex:0]; // data is declared in the .h file
data2 = [desc objectAtIndex:1];
[myTextField setString:data]; // myTextField is connected to an NSTextView in IB
[myTextField setString:data2];
How am I supposed to be writing the 4th and 5th lines? How / where do I release data and data2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不知道。您尚未从选择器包含
alloc
、new
或的方法接收到
或名称包含data
或data2
copyCreate
的函数,因此您不负责释放它们。看看 http://boredzo.org/cocoa-and-cocoa-touch -简介/。
You don't. You haven't received
data
ordata2
from a method with a selector containingalloc
,new
orcopy
or a function with a name containingCreate
, so you are not responsible for releasing them.Have a look at http://boredzo.org/cocoa-and-cocoa-touch-intro/.
修改 Cocoa 内存管理指南并确定这种情况下是否需要释放。关于
retain
和release
模式有非常具体但非常简单的规则。记住这些规则(双关语)。Revise the Cocoa Memory Management Guidelines and determine whether releasing is necessary in this case. There are very specific, yet very simple rules regarding a
retain
andrelease
pattern. Commit these rules to memory (pun intended).