• 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
Circular references caused by scheduled NSTimers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Circular references caused by scheduled NSTimers?


  • Subject: Circular references caused by scheduled NSTimers?
  • From: Oleg Krupnov <email@hidden>
  • Date: Fri, 19 Apr 2013 09:01:26 +0300

I recently encountered an alarming problem that I have never been
aware of, and I'd like to ask about the best practice to handle it.

Is it true that any object (let's call it Controller) that owns an
NSTimer, scheduled to fire a method (let's call it -timerDidFire) of
the same Controller, creates a circular reference and causes the
Controller to never be released and the timer never stop triggering?

It looks like scheduling the timer causes the run loop to retain a
reference to the object that implements -timerDidFire, in this case
it's the Controller. Is this true? Then this is a circular reference,
right?

In this case, if [_timer invalidate]; is called only in Controller's
dealloc, then the timer never stops firing?

Which is the best way to prevent this problem? Currently I'm thinking
about some kind of -[controller disconnect]; method that I need to
call before [controller release]; in controller's parent object, but
that seems a bit unwieldy solution.

Any other ideas/considerations? Thanks!
_______________________________________________

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: Circular references caused by scheduled NSTimers?
      • From: Charles Srstka <email@hidden>
    • Re: Circular references caused by scheduled NSTimers?
      • From: Greg Parker <email@hidden>
    • Re: Circular references caused by scheduled NSTimers?
      • From: Graham Cox <email@hidden>
  • Prev by Date: Re: ANN: new open-source window manager for OS X
  • Next by Date: Re: Circular references caused by scheduled NSTimers?
  • Previous by thread: Re: Attempts to restore unrestorable windows
  • Next by thread: Re: Circular references caused by scheduled NSTimers?
  • Index(es):
    • Date
    • Thread