• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Properties, Attributes and Retain+Autorelease
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Properties, Attributes and Retain+Autorelease
      • From: Markus Hanauska <email@hidden>
References: 
 >Re: Properties, Attributes and Retain+Autorelease (From: Matt Neuburg <email@hidden>)
 >Re: Properties, Attributes and Retain+Autorelease (From: Markus Hanauska <email@hidden>)

  • Prev by Date: Re: Activate app but bring only *one* window to the front
  • Next by Date: Re: Properties, Attributes and Retain+Autorelease
  • Previous by thread: Re: Properties, Attributes and Retain+Autorelease
  • Next by thread: Re: Properties, Attributes and Retain+Autorelease
  • Index(es):
    • Date
    • Thread