On Tue, Apr 27, 2010 at 2:05 PM, Keith Blount <[email protected]> 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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to