Re: literal strings - who do they belong to?
Re: literal strings - who do they belong to?
- Subject: Re: literal strings - who do they belong to?
- From: Wade Tregaskis <email@hidden>
- Date: Sun, 12 Jul 2009 22:55:47 -0700
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.
While your point is true, it's not actually a rebuttal - you can
assume objects returned from such methods are autoreleased, because
that's the contract given. Whether they're cached or singletons or
whatever else, they must obey the policy that they'll stick around
'til the next flush of the current thread's current autorelease pool.
You just can't safely handle the memory management otherwise,
especially in multithreaded cases.
Unfortunately, this contract isn't always followed. Lots of people
"optimise" away this policy instead of doing a "superfluous" 'return
[[foo retain] autorelease]'. @propertys are by default atomic
(meaning they follow this policy) for a reason. In manually written
code, you have to be careful, but you're pretty safe with object
creation methods, and especially those in Apple frameworks. If you
find any that don't follow this policy, you should file a bug report.
Wade
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden