开发者

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* li开发者_如何学JAVAnk;

@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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜