• 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: Strange retainCount from NSTimer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange retainCount from NSTimer


  • Subject: Re: Strange retainCount from NSTimer
  • From: "Michael Ash" <email@hidden>
  • Date: Thu, 13 Mar 2008 23:06:53 -0400

On Thu, Mar 13, 2008 at 9:37 PM, Brian Greenstone <email@hidden> wrote:
> I'm hoping someone can shed some light on this for me.  I'm getting
>  some unusual retainCount values from the following code:
>
>         NSTimer *theTimer;
>
>         theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
>                                                         target:         self
>                                                         selector:       @selector(timerCallback)
>                                                         userInfo:       nil
>                                                         repeats:        YES];
>
>         NSLog(@"A: retain count: %i", [theTimer retainCount]);
>
>         [[NSRunLoop currentRunLoop] addTimer: theTimer forMode:
>  NSDefaultRunLoopMode];
>
>         NSLog(@"B: retain count: %i", [theTimer retainCount]);
>
>
>  The output I get is:
>
>         A: retain count: 2
>         B: retain count: 2
>
>
>  But that shouldn't be, right?  Shouldn't the retainCount of theTimer
>  be 1 after scheduledTimerWithTimeInterval?  Then shouldn't it be
>  bumped up to 2 after adding the timer to the Run Loop?

The timer creation *already* adds it to the runloop (this is why it
has "scheduled" in the name), which gives you a retain count of 2 and
causes the manual scheduling to do nothing at all.

Mike
_______________________________________________

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

References: 
 >Strange retainCount from NSTimer (From: Brian Greenstone <email@hidden>)

  • Prev by Date: Re: get currently logging in users
  • Next by Date: Re: sorting large tables
  • Previous by thread: Re: Strange retainCount from NSTimer
  • Next by thread: Can core data save to a remote file?
  • Index(es):
    • Date
    • Thread