开发者

Does assignment to a property cause a retain?

开发者 https://www.devze.com 2023-03-22 17:02 出处:网络
A very basic question, when I have something like: TTStyledText * text = [TTStyledText textFromXHTML:message.message lineBreaks:YES URLs:NO];

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

精彩评论

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