Re: NSString uppercaseString
Re: NSString uppercaseString
- Subject: Re: NSString uppercaseString
- From: email@hidden
- Date: Fri, 27 Jun 2008 15:48:22 +0200
On 27 Jun 2008, at 3:30pm, Uli Kusterer wrote:
If you read the documentation closely, you'll see that it would be
perfectly valid to implement this method so the string goes away
when the original (non-uppercase) string is released.
Hmmm, not sure I'd read it that way (depending on what you are reading).
According to: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/ObjectOwnership.html
*****
Validity of Shared Objects
Cocoa’s ownership policy specifies that received objects should remain
valid throughout the scope of the calling method. It should also be
possible to return a received object from the current scope without
fear of it being released. It should not matter to your application
that the getter method of an object returns a cached instance variable
or a computed value. What matters is that the object remains valid for
the time you need it.
There are exceptions to this rule. For example, collection classes do
not attempt to extend the lifetime of objects placed inside them.
Removing an object from a mutable array could invalidate any copies of
the object previously acquired, as in the following example:
value = [array objectAtIndex:n];
[array removeObjectAtIndex:n];
// value could now be invalid.
*****
Since there is no explicit mention that uppercaseString is an
exception to this, I think the string will always be valid in such
cases as:
NSString* someString = [NSString alloc] initWithWhatever:whatever];
NSString* someOtherString = [someString uppercaseString];
[someString release];
Matt Gough_______________________________________________
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