Re: Avoiding mutual retain cycles
Re: Avoiding mutual retain cycles
- Subject: Re: Avoiding mutual retain cycles
- From: Andreas Mayer <email@hidden>
- Date: Tue, 22 Jul 2008 04:49:30 +0200
Am 21.07.2008 um 22:02 Uhr schrieb Markus Spoettl:
For example NSCollectionView, NSCollectionViewItem and its view. One
may or may not suspect the NSCollectionViewItem owns the
corresponding view. It may as well not own it and instead the
NSCollectionView owns both.
I don't know why you'd think the collection view might own the item's
view. You set the view for the view item, so the hierarchy seems to be
quite clear. (The collection view *might* retain the view too. That's
an implementation detail.)
Of course once you run into a retain cycle problem with this and no
NSCollectionViewItem ever gets released because of it (like I did)
you quickly learn why and who owns the view.
How would you get a retain cycle here? You just hold on to the
collection view. Everything else should not be your responsibility.
I have to point out that I did not actually use those classes yet.
(Instead I built something similar myself for 10.4. compatibility.) So
I might be wrong here; I'd be surprised though.
The point is, unless this is documented explicitly the ownership
relations are not clear all the time.
If you set something, it's usually retained. Exceptions from this norm
should certainly be documented - like it is with delegates.
Andreas
_______________________________________________
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