Re: When does an object own its instance variable?
Re: When does an object own its instance variable?
- Subject: Re: When does an object own its instance variable?
- From: mmalc crawford <email@hidden>
- Date: Fri, 17 Aug 2007 09:07:09 -0700
On Aug 17, 2007, at 3:37 AM, Tony Wroblewski wrote:
[...]
Please do not reproduce the memory management rules especially if you
present them in an incomplete or incorrect fashion.
They are laid out, completely and correctly, at <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html
> and explained in greater detail in the rest of that document.
The correct way would be
NSString *string = [[NSString stringWithString:@"hello] retain];
It's not clear in what context this would be correct.
If you simply want a string constant, you can just use:
NSString *string = @"hello";
If you want to create a new string from an existing string, it is
typically better (more efficient) to use:
NSString *string = [otherString copy];
since this will only make a copy if 'string' is an instance of
NSMutableString, otherwise it will just retain it.
If you really want another object, you can use:
NSString *string = [[NSString alloc] initWithString:otherString];
mmalc
_______________________________________________
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