• 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: stringByReplacingCharactersInRange leading to bus error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringByReplacingCharactersInRange leading to bus error


  • Subject: Re: stringByReplacingCharactersInRange leading to bus error
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 18 Aug 2010 14:23:32 -0700

On Wed, Aug 18, 2010 at 2:08 PM, Sherm Pendley <email@hidden> wrote:
> The caller is doing nothing wrong here. It's finished using foo, and
> released it. If the caller's only use of bar is within the scope of
> the calling method, it's under no obligation to retain it. It's the
> responsibility of -stringByReplacing... to return an object that
> remains valid throughout the caller's scope, even if the original
> string is released. Doing "return [[self retain] autorelease]"
> fulfills that responsibility; "return self" does not.

Meh, this all boils down to caller vs. callee responsibility. I tend
to think in terms of caller responsibility, but the documentation
seems to prefer callee responsibility *except* in the case of
collection classes or parent/child relationships:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html

I suppose I should agree that not requiring the caller to retain an
object for its own scope is preferable, but most of the times this
issue pops up for me are in fact parent/child relationships.

> Indeed, on that very page, at
> <http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/Articles/mmAccessorMethods.html#//apple_ref/doc/uid/TP40003539-SW6>,
> it gives this example:

It gives it as one example of three, the other two not having
performing an immediate retain/autorelease pair.

--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: stringByReplacingCharactersInRange leading to bus error
      • From: Sherm Pendley <email@hidden>
    • Re: stringByReplacingCharactersInRange leading to bus error
      • From: Greg Parker <email@hidden>
References: 
 >stringByReplacingCharactersInRange leading to bus error (From: James Miller <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: "John C. Randolph" <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Murat Konar <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Sherm Pendley <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Kyle Sluder <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Sherm Pendley <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Kyle Sluder <email@hidden>)
 >Re: stringByReplacingCharactersInRange leading to bus error (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: stringByReplacingCharactersInRange leading to bus error
  • Next by Date: Re: stringByReplacingCharactersInRange leading to bus error
  • Previous by thread: Re: stringByReplacingCharactersInRange leading to bus error
  • Next by thread: Re: stringByReplacingCharactersInRange leading to bus error
  • Index(es):
    • Date
    • Thread