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

memory mgmt in convenience and accessor methods


  • Subject: memory mgmt in convenience and accessor methods
  • From: Daniel Child <email@hidden>
  • Date: Tue, 29 May 2007 12:49:09 -0400

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];
}

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. In other words:

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

-(int) instVar {
	return instVar;
}

Thanks for looking.

Daniel
_______________________________________________

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: "Clark Cox" <email@hidden>
  • Prev by Date: Re: observing dealloc
  • Next by Date: Re: memory mgmt in convenience and accessor methods
  • Previous by thread: Re: Window freezes app
  • Next by thread: Re: memory mgmt in convenience and accessor methods
  • Index(es):
    • Date
    • Thread