Re: Properties, Attributes and Retain+Autorelease
Re: Properties, Attributes and Retain+Autorelease
- Subject: Re: Properties, Attributes and Retain+Autorelease
- From: Kyle Sluder <email@hidden>
- Date: Wed, 29 Jun 2011 10:17:03 -0700
On Wed, Jun 29, 2011 at 10:08 AM, Markus Hanauska <email@hidden> wrote:
> Since when do you have to be owner of an object to be allowed to interact with it?
You're holding on to the result of -value. Therefore you need an
ownership reference to it.
This is something Cocoa programmers have needed to worry about
forever. The canonical example is this:
id o = [myArray objectAtIndex:0];
[myArray release];
NSLog(@"%@", [o description]); // <-- CAN CRASH HERE
Unless you know you have ownership of the object (directly by
retaining it, or indirectly by owning something else that has an
owning reference to the object), you can't assume your pointer to the
object is valid.
> This contradicts pretty much everything Apple has ever documented about Cocoa/Obj-C.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447-1000922-BABBFBGJ
--Kyle Sluder
_______________________________________________
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