• 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: Fastest way to check for descendants of an object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fastest way to check for descendants of an object


  • Subject: Re: Fastest way to check for descendants of an object
  • From: Michael Ash <email@hidden>
  • Date: Tue, 27 Apr 2010 19:18:02 -0400

On Tue, Apr 27, 2010 at 2:05 PM, Keith Blount <email@hidden> wrote:
> Indeed, I believe that's my problem - currently when I add objects to my children array I do things such as [[myNode children] addObject:newNode], meaning I have nowhere to catch it. I'll update my code to add some accessors as you suggest, and change my - (NSMutableArray *)children accessor to - (NSArray *)children so that the compiler can catch any slips where I try to manipulate it directly. Regarding the weak reference to the parent, I guess I don't need to worry about that getting released because if it is, then so will the children be, or else by then they will refer to a different parent object.

One pattern which can help prevent memory management trouble with this
sort of thing is to always zero out the weak reference any time a
child is removed or the parent is destroyed. Do a setParent:nil when
you remove children, and set all of your children's parents to nil in
dealloc, and that will ensure that they don't end up trying to message
a stale reference.

Mike
_______________________________________________

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

References: 
 >Fastest way to check for descendants of an object (From: Keith Blount <email@hidden>)
 >Re: Fastest way to check for descendants of an object (From: Mike Abdullah <email@hidden>)
 >Re: Fastest way to check for descendants of an object (From: Keith Blount <email@hidden>)
 >Re: Fastest way to check for descendants of an object (From: Mike Abdullah <email@hidden>)
 >Re: Fastest way to check for descendants of an object (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: NSApplicationMain question
  • Next by Date: Re: menu madness with retain count
  • Previous by thread: Re: Fastest way to check for descendants of an object
  • Next by thread: Re: Fastest way to check for descendants of an object
  • Index(es):
    • Date
    • Thread