开发者

On properties and accessors

开发者 https://www.devze.com 2023-04-10 01:23 出处:网络
Assuming that header declaration contains @property(nonatomic, assign) DoublyLinkedList *doublyLinkedList;

Assuming that header declaration contains

@property(nonatomic, assign) DoublyLinkedList *doublyLinkedList;

Is there any difference between

[[self doublyLinkedList] release];
[self setDoublyLinkedList:nil];

and

[doub开发者_StackOverflowlyLinkedList release];
doublyLinkedList= nil

Is one preferred over another? Why?


There is no difference.

The second option might be ever so slightly faster, because it doesn't use the getter/setter methods.

Just so we're clear, are you retaining doublyLinkedList when you assign it? Because otherwise you're over-releasing.

And unless you have a good reason, I would skip all this and use retain instead of assign, and self.doublyLinkedList = nil to release/clear it.

e.g.

definition

@property(nonatomic, retain) DoublyLinkedList *doublyLinkedList;

in use

self.doublyLinkedList = nil;

and on dealloc

-(void)dealloc{self.doublyLinkedList=nil;[super dealloc];}
0

精彩评论

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

关注公众号