当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Setting text for NSTextView with an NSString variable, considering reference counting

问题描述:

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?

网友答案:

You don't. You haven't received data or data2 from a method with a selector containing alloc, new or copy or a function with a name containing Create, so you are not responsible for releasing them.

Have a look at http://boredzo.org/cocoa-and-cocoa-touch-intro/.

网友答案:

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 and release pattern. Commit these rules to memory (pun intended).

分享给朋友:
您可能感兴趣的文章:
随机阅读: