views:

165

answers:

2

I have this structure:

@interface MyList : NSObject {
    NSString* operation;
    NSString* link;
}

@property (readwrite) NSString* operation;
@property (readwrite, assign) NSString* link;

@end


@implementation MyList
@synthesize operation,link;
@end

I know that if I had retain instead of readwrite I should release the operation and link properties.

BUT should I release the operation and link with the code above?

+3  A: 

No. You did not New, Alloc, Retain, or Copy the values in there, so you do not (Auto)release them.

Dave DeLong
Narc, narc, narc!
bbum
cran(berry)! cran(berry)! cran(berry)!
Dave DeLong
carn(al knowledge)...
JeremyP
+3  A: 

The default values are readwrite, assign, and atomic. So by not specifying assign, retain, or copy in your first example you are essentially using assign by default. This is why you wouldn't subsequently use a release. Assign does not increase the retain count of an object. Note that for objects such as your string you almost would never want to use assign because you don't own the object and it could get released on you. So for objects you want to use either retain or copy. You would only use assign on scalar types like floats, NSIntegers, BOOLs etc. Note also that if you are not using garbage collection you get a compiler warning if you don't specify assign, retain, or copy.

regulus6633
You *would* assign with objects to avoid circular references (e.g. delegates are usually not retained). This is probably not the case with an NSString, though.
Chuck