Re: stringByReplacingCharactersInRange leading to bus error
Re: stringByReplacingCharactersInRange leading to bus error
- Subject: Re: stringByReplacingCharactersInRange leading to bus error
- From: Martin Wierschin <email@hidden>
- Date: Wed, 18 Aug 2010 14:57:15 -0700
Implementing -stringByReplacing... as "return [[self retain]
autorelease];" makes the same guarantee, that the object returned by
-stringByReplacing... will remain valid if the original string is
released.
Yes, but there's no guarantee which technique -stringByReplacing..
will use internally.
True, but the MM rules *do* guarantee that -stringByReplacing...*
will return an object that remains valid throughout the caller's
scope.
Ah, you're right. I reread the memory management documentation and it
is guaranteed:
"A received object is normally guaranteed to remain valid within the
method it was received in, and that method may also safely return the
object to its invoker. Exceptions include..."
None of the listed exceptions apply to our string replacement example.
I feel silly getting something so fundamental wrong, though in my
defense I feel like Apple must have added that guarantee at some point
over the years. A good idea to be sure.
* Is anyone else wishing that we'd chosen a shorter method name to
have this discussion? :-)
We could have done worse :P
~Martin
_______________________________________________
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