On 2011-06-29, at 20:08 , Matt Neuburg wrote:
> On Jun 29, 2011, at 10:39 AM, Markus Hanauska wrote:
>> If that was allowed, one would have to write code like this:
>> id value = [someObject value];
>> [value retain];
>> [someOtherObject setValue:value];
>> [value release];
> That's silly. You didn't release someObject this time, so now there's no need to worry about the lifetime of value.
That's assuming that setValue of someOtherObject is not doing "anything" in the system (call a method, maybe posting a notification, altering a singleton or a global variable, etc.) which may cause value to be released... and I can not guarantee so, unless I know for sure that value is either retained or at least retain+autorelease. Since almost all Cocoa objects from Apple will return value retain+autorelease, this can indeed not happen, but hey, it wasn't me claiming it's perfectly okay that nonatomic getters don't return objects retain+autorelease and that this will not break anything, because it's totally okay if objects you don't own unexpectedly cease to live. I posted code that showed how this can easily happen, haven't you read it? Shall I make a compilable project for you, so you can see it "crashing" yourself?
I personally think a getter should always return objects retain+autorelease and that no matter if it is atomic or not. This is certainly not the best thing performance-wise, but it is the safest way to return values in a complex system where you don't know which implications simple method calls really have under the hood. E.g. you can skip the retain+autorelease dance when you use private objects in your own framework that you don't expose to the public or properties not visible outside your framework (they are just for internal use), but for all methods you are going to expose only the retain+autorelease dance guarantees safety.
Which brings me back to my original questions, e.g. whether an "assign" property returns values retain+autorelease when atomic and not when nonatomic... or does it always return the value not retain+autorelease since "assign" properties ignore the nonatomic flag anyway, since there is nothing to be done, they are atomic anyway by definition.
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