• 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: Observing with GC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Observing with GC


  • Subject: Re: Observing with GC
  • From: Chris Suter <email@hidden>
  • Date: Tue, 26 Feb 2008 21:42:06 +1100


On 26/02/2008, at 7:01 PM, Quincey Morris wrote:

I find it hard to see anything dangerous in the finalize strategy used in the above code, unless:

(a) there's a possibility that the observer is being finalized around the same time, or

(b) the finalize method tries to set one of the observee's own properties (thus triggering a notification to the observer, which could perhaps zombify the observee if the observer stored its pointer)

The observation info uses a weak reference and it will have been zeroed before finalize is called so neither of the above are a problem. Even so, I'm not sure it's a good idea to call removeObserver: from the finalize method.


Knowing this, you might wonder if you have to call removeObserver at all in the GC case. I just ran some tests and it looks like you do otherwise you'll get a memory leak which is a shame because it would be easy to clean up automatically.

On a side note, it doesn't look like you have to call removeObserver: for notifications registered with NSNotificationCenter.

- Chris

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: Observing with GC
      • From: Antonio Nunes <email@hidden>
    • Re: Observing with GC
      • From: Quincey Morris <email@hidden>
References: 
 >Observing with GC (From: Quincey Morris <email@hidden>)
 >Re: Observing with GC (From: Rob Keniger <email@hidden>)
 >Re: Observing with GC (From: glenn andreas <email@hidden>)
 >Re: Observing with GC (From: Rob Keniger <email@hidden>)
 >Re: Observing with GC (From: Bill Bumgarner <email@hidden>)
 >Re: Observing with GC (From: Quincey Morris <email@hidden>)

  • Prev by Date: Nicely scaling a CALayer (interpolation?)
  • Next by Date: Event Logging
  • Previous by thread: Re: Observing with GC
  • Next by thread: Re: Observing with GC
  • Index(es):
    • Date
    • Thread