On Jul 21, 2008, at 12:21 PM, Andreas Mayer wrote:
I'm wondering if there is a general rule or mechanism that suggests what to do in such a case.

About retain cycles:

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/ObjectOwnership.html

"The solution to the problem of retain cycles is that the “parent” object should retain its “children,” but that the children should not retain their parents."

For instance, how are delegates implemented in AppKit, are they retained?

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/chapter_6_section_4.html

"Delegating objects do not (and should not) retain their delegates."

Thanks for those links.

But there are still cases where it is unknown which of the objects is going to be released first

Care to name one?

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. 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.

The point is, unless this is documented explicitly the ownership relations are not clear all the time.

I generally do not find it difficult to decide which object needs to own which. In case you can't decide, maybe neither should and you are better off adding a third object that handles both.


Agreed, if it's in your own power and you know what your structure looks like it's simple.

Regards
Markus
--
__________________________________________
Markus Spoettl

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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