adit
adit

Reputation: 33674

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?

Upvotes: 0

Views: 105

Answers (2)

bbum
bbum

Reputation: 162722

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).

Upvotes: 6

Chuck
Chuck

Reputation: 237110

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.

Upvotes: 4

Related Questions