• 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: "Clark Cox" <email@hidden>
  • Date: Tue, 29 May 2007 09:54:39 -0700

On 5/29/07, Daniel Child <email@hidden> wrote:
Hi All,

I am trying to build some basic test classes and am trying to learn
the appropriate setup for accessors and inits and convenience
methods. While various sources recommend having a "preferred init"
method for each class (the most complicated one), I am wondering if a
similar principle applies to "constructor" (convenience?) methods. Is
the following code ill-advised for any reason? I am in particular
wondering about the double autoreleasing.

+(id) newThing {
        id newThg = [[self alloc] init];
        return [newThg autorelease];
}

+(id) newThingWithStg: (int)val {
        id newThg = [Thing newThing];
        [newThg setInstVar: val];
        return [newThg autorelease];

You've just autoreleased newThg a second time. Don't do that :)

}

Also, while there are three memory management strategies recommended
for the accessors, I am wondering if any retains are needed if the
instance variables are primitive data types.

No, they aren't.

In other words:

-(void) setInstVar: (int) val {
        instVar = val; // OK without retains / releases ??
}

-(int) instVar {
        return instVar;
}

If the instance vars are primitive types, then retains/releases aren't even possible, much less required.

--
Clark S. Cox III
email@hidden
_______________________________________________

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


  • Follow-Ups:
    • Re: memory mgmt in convenience and accessor methods
      • From: Uli Kusterer <email@hidden>
    • Re: memory mgmt in convenience and accessor methods
      • From: Daniel Child <email@hidden>
References: 
 >memory mgmt in convenience and accessor methods (From: Daniel Child <email@hidden>)

  • Prev by Date: memory mgmt in convenience and accessor methods
  • Next by Date: Re: RS: What's the difference?
  • Previous by thread: memory mgmt in convenience and accessor methods
  • Next by thread: Re: memory mgmt in convenience and accessor methods
  • Index(es):
    • Date
    • Thread