views:

253

answers:

2

Does the setTitle method of UIButton retain the NSString passed as argument ?

I guess I can rely on the fact that the property is defined as:

property(nonatomic,readonly,retain) UILabel *titleLabel

In this case, I think that it does retain the string.

Thanks, Apple92

A: 

Yes - you've pretty much answered your own question there.

Not all API's retain as the original NSString may change in some way - one API may receive an NSString reference, but it's actually an NSMutableString, for exapmle.

The Google coding standards for Objective C has a section about this, here

JBRWilkinson
+1  A: 

You can count on framework classes to retain things that they need unless otherwise documented. This is part of Cocoa's memory management rules. You should read that document and let it sink in, because once you understand it, basically all of your memory management questions go away — conversely, if you don't take the time to understand that document, you'll always feel uncertain. Luckily, it's pretty simple.

Also, I would be careful about relying too much on other people telling you the rules. Especially in informal settings like Stack Overflow, people have a tendency to simplify and misspeak, leading to misunderstandings — meanwhile, the official rules have been proofread many, many times over the years.

Chuck