开发者

Does assignment to a property cause a retain?

A very basic question, when I have something like:

 TTStyledText * text = [TTStyledText textFromXHTML:message.message lineBreaks:YES URLs:NO];
 text.width = self.frame.size.width - 60;
 text.font = [UIFont fontWithName:@"ArialMT" size:17.0];
 _main_title.text = text;开发者_开发知识库

When I assign text to _main_title.text, does it mean that _main_title.text retains text?


Actually, it means that you shouldn't care if _main_title.text retains text or not.

That would be entirely an implementation detail of the setter method. It might copy the text. It might do something whacky internally. You shouldn't need to know.

You should only need to worry about the memory management in your code and, in that code, your memory management is correct.

Finally, if you want text to survive beyond the end of that particular scope, then you should retain it (and release it later).


It depends. If text is a retain property of whatever class _main_title belongs to, or _main_title's class implements a setText: method that retains its argument, then yes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜