• 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: literal strings - who do they belong to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: literal strings - who do they belong to?


  • Subject: Re: literal strings - who do they belong to?
  • From: BJ Homer <email@hidden>
  • Date: Mon, 13 Jul 2009 00:43:12 -0600

>
> But then I saw the case where I have an object which returns, as a method
> result or a property, one of its instance variables. The caller holds on to
> it (without retaining it) then releases (and deallocs) my object.  My object
> releases its instance variables which results in the caller holding a
> reference to a dead value.
>
> {
>  Object *o = [Object new];
>  NSString *s = o.somevalue;            // gets o's instance variable
> (without retain)
>  [o release];                          // o's instance variable is released
>  NSLog(@"Crash: %@",s)                 // accesses dead string
> }
>
> So, yes, the retain/autorelease isn't superfluous at all, though the usage
> pattern that would trigger the problem seems relatively unlikely (in my
> example, o seems far more likely to be autorelease'd).  Is there a more
> common case that I'm missing?


If o were in an NSDictionary that was passed to you in a parameter, for
example, and you removed the key from the dictionary, you'd trigger the same
problem.

-BJ
_______________________________________________

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

References: 
 >literal strings - who do they belong to? (From: William Squires <email@hidden>)
 >Re: literal strings - who do they belong to? (From: Bill Bumgarner <email@hidden>)
 >Re: literal strings - who do they belong to? (From: Peter N Lewis <email@hidden>)
 >Re: literal strings - who do they belong to? (From: Wade Tregaskis <email@hidden>)
 >RE: literal strings - who do they belong to? (From: Jeff Laing <email@hidden>)

  • Prev by Date: Re: [iPhone] Addressbook "group" problem
  • Next by Date: Re: [iPhone] Addressbook "group" problem
  • Previous by thread: RE: literal strings - who do they belong to?
  • Next by thread: Re: literal strings - who do they belong to?
  • Index(es):
    • Date
    • Thread