memory mgmt in convenience and accessor methods
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