okami
okami

Reputation: 2153

dealloc properties with assign and readwrite objective-c

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?

Upvotes: 0

Views: 1145

Answers (2)

regulus6633
regulus6633

Reputation: 19032

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.

Upvotes: 3

Dave DeLong
Dave DeLong

Reputation: 243146

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

Upvotes: 3

Related Questions