Re: Manual reference counting and doubly-linked lists
Re: Manual reference counting and doubly-linked lists
- Subject: Re: Manual reference counting and doubly-linked lists
- From: Roland King <email@hidden>
- Date: Thu, 15 Nov 2012 18:23:19 +0800
On 15 Nov, 2012, at 12:47 PM, Daniel DeCovnick <email@hidden> wrote:
> Strong/retain for next, weak/assign for previous.
> On Nov 14, 2012, at 7:59 PM, William Squires wrote:
>
>>
>> @interface DoublyLinkedListClass
>>
>> @property (nonatomic, retain) Thing *head;
>>
>> @end
>>
>> "doublist.m"
>> @implementation DoublyLinkedListClass
>>
>> @synthesize head = _head;
>>
>> …
>>
>> -(void)dealloc
>> {
>> self.head = nil; // Is this begging for a problem?
> no in ARC (but it's unnecessary), yes in MRC; you should [head release]; instead, or you'll leak memory.
>
> -Dan
Since the property is declared retain then setting it nil will release it just as [ _head release ] would (_head is the actual iVar), so no leak there, and that will begin the collapse the whole chain of linked objects.
I'll leave the debate about property accessors vs direct variable access in init and dealloc well alone, either will work.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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