On 12/07/2009, at 23:23 , Ben Cox wrote:
NSString +stringByAppendingString:(NSString*) returns an autoreleased
string. If you release it explicitly, your application will crash.

On 13/07/2009, at 0:02 , Bill Bumgarner wrote:
After the second assignment, htmlString is no longer a literal string, but will be a reference to whatever is returned by - stringByAppendingString:.

That would be an autoreleased string so, no, the -release isn't necessary.


I know you guys probably know this, but to be technically accurate, there is no guarantee the return value of stringByAppendingString returns an autoreleased string.

All you know is that it returns a string *you do not own*. You are not responsible for releasing it, and you are responsible for retaining it if you want it to stick around.

For example, [immutablestr stringByAppendingString:@""] quite possibly just returns. [immutablestr stringByAppendingString:@"Fred"] called twice in a row might return the same string both times. You don't know, and you should not care.

The memory management rules say nothing about "autoreleased" or "retain count".

This is largely irrelevant and trivial if you know the rules - but if you don't know the rules it is important not to misunderstand the distinction.

Enjoy,
   Peter.

--

     Clipboard Switching and Macros with Keyboard Maestro

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>




_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to