• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Manual reference counting and doubly-linked lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Manual reference counting and doubly-linked lists


  • Subject: Re: Manual reference counting and doubly-linked lists
  • From: Daniel DeCovnick <email@hidden>
  • Date: Wed, 14 Nov 2012 20:47:25 -0800

Strong/retain for next, weak/assign for previous.
On Nov 14, 2012, at 7:59 PM, William Squires wrote:

> Let's say I have:
>
> @interface Thing : NSObject
>
> @property (nonatomic, ???) Thing *nextThing;
> @property (nonatomic, ???) Thing *prevThing;
>
> @end
>
> and somewhere I keep a reference to the 'head' of this doubly-linked list. What should ??? be, "retain", or "assign" in order to work properly? If I was using ARC instead, would they be "strong" or "weak"? Assuming the list doesn't contain circular references (i.e. a<->b<->c<->a) will releasing my 'head' reference properly clean up if I have:
>
> "doublist.h"
> @class Thing;
>
> @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
_______________________________________________

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


  • Follow-Ups:
    • Re: Manual reference counting and doubly-linked lists
      • From: Roland King <email@hidden>
References: 
 >Manual reference counting and doubly-linked lists (From: William Squires <email@hidden>)

  • Prev by Date: Manual reference counting and doubly-linked lists
  • Next by Date: Re: Mysterious crash report
  • Previous by thread: Manual reference counting and doubly-linked lists
  • Next by thread: Re: Manual reference counting and doubly-linked lists
  • Index(es):
    • Date
    • Thread