• 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: memory mgmt in convenience and accessor methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory mgmt in convenience and accessor methods


  • Subject: Re: memory mgmt in convenience and accessor methods
  • From: Daniel Child <email@hidden>
  • Date: Tue, 29 May 2007 21:50:47 -0400

Thanks, Clark. This helps a lot, especially the "you make it you 'break' (release) it" part. I have renamed my methods as well.

On May 29, 2007, at 3:32 PM, Clark Cox wrote:

You take ownership of an object if you create it using a method whose
name begins with "alloc" or "new" or contains "copy" (for example,
alloc, newObject, or mutableCopy), or if you send it a retain message.
You are responsible for relinquishing ownership of objects you own
using release or autorelease. Any other time you receive an object,
you must not release it."

So, following the rules: (BTW, using newXXX as the name for a method
like this is generally a bad idea; because it conflicts with the rule
stated above, I've renamed them for you):

+(id)thing {
   id newThg = [[self alloc] init];

/* I created it (by calling +alloc), so I am responsible for releasing it */
return [newThg autorelease];
}


+(id)thingWithStg: (int)val {
   id newThg = [Thing thing];
   [newThg setInstVar: val];

   /* I didn't create it (+newThing did) so I am not responsible for
releasing it */
   return newThg;
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >memory mgmt in convenience and accessor methods (From: Daniel Child <email@hidden>)
 >Re: memory mgmt in convenience and accessor methods (From: "Clark Cox" <email@hidden>)
 >Re: memory mgmt in convenience and accessor methods (From: Daniel Child <email@hidden>)
 >Re: memory mgmt in convenience and accessor methods (From: "Clark Cox" <email@hidden>)

  • Prev by Date: Re: Places to go for a new Cocoa developer?
  • Next by Date: Re: NSTableColumn 'enabled' binding not in 10.3? Any others?
  • Previous by thread: Re: memory mgmt in convenience and accessor methods
  • Next by thread: Re: memory mgmt in convenience and accessor methods
  • Index(es):
    • Date
    • Thread