• 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: Avoiding mutual retain cycles
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Avoiding mutual retain cycles


  • Subject: Re: Avoiding mutual retain cycles
  • From: Markus Spoettl <email@hidden>
  • Date: Mon, 21 Jul 2008 20:24:42 -0700

On Jul 21, 2008, at 7:23 PM, Michael Ash wrote:
Without investigating things more deeply, just from the basic stuff I
know about the classes in question, I'd assume that the
NSCollectionView owns the NSCollectionViewItems and the views, and the
NSCollectionViewItems would also own the views. Where is the retain
cycle?


Well there is none in the default setup, of course. But here's a non far-fetched example to easily create one.

If you're implementing a custom NSView that for some reason has to have access to the NSCollectionViewItem or NSCollectionView it belongs to, the only proper way to do so (in the collection view world) is by accessing the NSCollectionViewItem which has a -collectionView method that returns the collection view.

So you need a way back and this you do with a pointer to the NSCollectionViewItem in a suitable place. As you don't know the ownership circumstances of NSCollectionViewItem and its view the safest thing to do is to retain the NSCollectionViewItem in the view. There's the retain cycle, because - as it turns out - the NSCollectionViewItem seems to retain the view.

The point of all this is not that it's avoided easily - which it is. The point is that you can't know the circumstances unless it's documented and the original question was how AppKit does avoid things like that.

Now that I read more on retain cycles it's clear there is no ingenious Cocoa solution to this problem, just plain old defensive programming techniques - which is what I was wondering about.

Regards
Markus
--
__________________________________________
Markus Spoettl

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

_______________________________________________

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: Avoiding mutual retain cycles
      • From: "Michael Ash" <email@hidden>
References: 
 >Avoiding mutual retain cycles (From: Markus Spoettl <email@hidden>)
 >Re: Avoiding mutual retain cycles (From: Andreas Mayer <email@hidden>)
 >Re: Avoiding mutual retain cycles (From: Markus Spoettl <email@hidden>)
 >Re: Avoiding mutual retain cycles (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Breakpoints for CG* functions
  • Next by Date: Re: Crash drawing shadows
  • Previous by thread: Re: Avoiding mutual retain cycles
  • Next by thread: Re: Avoiding mutual retain cycles
  • Index(es):
    • Date
    • Thread