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

Re: Unwanted retain


  • Subject: Re: Unwanted retain
  • From: "b.bum" <email@hidden>
  • Date: Thu, 5 Feb 2004 18:13:16 -0800

On Feb 5, 2004, at 5:05 PM, Ryan Bates wrote:
On 5 Feb, 2004, at 9:27 AM, b.bum wrote:
While Clark might be correct, it is completely and totally irrelevant to consider what the run loop might or might not be doing to the retain count of the timer. Reading the documentation for NSTimer and NSRunLoop, neither mention anything about retaining the timer. While the Run Loop might retain the timer for its own purposes, that is none of your business as a Cocoa developer! :-)

While I agree it is irrelevant, the Apple docs do say the run loop retains the timer:

"Note that run loops retain their timers, so you can release the timer after you have added it to a run loop."
<http://developer.apple.com/documentation/Cocoa/Conceptual/Timers/ Tasks/createtimer.html>

Here are a couple of rules that might help everyone with NSTimers (and hopefully won't cause extra confusion):
- A timer retains the target and userInfo objects.
- A timer is automatically retained by the run loop when scheduling it.
- If a timer is not set to repeat, it will automatically invalidate itself upon firing.
- A timer is released from the run loop when calling invalidate.
- A timer releases the target and userInfo objects when calling invalidate.

Dang. Hit deliver too soon.

One important clarification (to continue to flog that horse!):

If you create the timer and assign it to an instance variable, then invoke -retain!

Do not invoke -invalidate unless you have -retain'd the Timer or if you have an autorelease'd timer and are still within the scope of the autorelease'd reference.

If the timer is one-shot, it will fire once and invalidate, removing itself from the run loop (and being -release'd in the process). If you happen to have a non-retain'd reference around, calling -invalidate (or any other method) at some later time will cause your app to crash.

b.bum
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Unwanted retain (From: Lorenzo <email@hidden>)
 >Re: Unwanted retain (From: Dustin Voss <email@hidden>)
 >Re: Unwanted retain (From: "b.bum" <email@hidden>)
 >Re: Unwanted retain (From: Clark Cox <email@hidden>)
 >Re: Unwanted retain (From: "b.bum" <email@hidden>)
 >Re: Unwanted retain (From: Dustin Voss <email@hidden>)
 >Re: Unwanted retain (From: Ryan Bates <email@hidden>)

  • Prev by Date: newbie design question
  • Next by Date: Re: base64
  • Previous by thread: Re: Unwanted retain
  • Next by thread: Re: Unwanted retain
  • Index(es):
    • Date
    • Thread