• 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: When does an object own its instance variable?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >When does an object own its instance variable? (From: Bob Ueland <email@hidden>)
 >Re: When does an object own its instance variable? (From: Tony Wroblewski <email@hidden>)
 >Re: When does an object own its instance variable? (From: Tony Wroblewski <email@hidden>)

  • Prev by Date: Re: NSWindow behavior
  • Next by Date: Re: modifying info dictionary
  • Previous by thread: Re: When does an object own its instance variable?
  • Next by thread: Re: When does an object own its instance variable?
  • Index(es):
    • Date
    • Thread