• 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: to implement a 1 sec repeating timer in a separate thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: to implement a 1 sec repeating timer in a separate thread


  • Subject: Re: to implement a 1 sec repeating timer in a separate thread
  • From: Nick Rogers <email@hidden>
  • Date: Thu, 22 Oct 2009 16:18:03 +0530

Hi,
Thanks for the reply. My question was very vague, I admit.
But now I have moved to your suggestion.
I'm setting up the timer via [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(doSomething:) userInfo: nil repeats: YES];
But the doSomething is not getting called at all.
May be because this thread is busy doing something else, so do I have to setup the timer in say main Thread.
Earlier I was doing so, by setting up the timer by calling this setting up method as [self performSelectorOnMainThread:............], and it was working, but even after invalidating the timer, the timer was still referencing the object that contained NSTimer *timer.


Any suggestions?
Nick

On 22-Oct-2009, at 2:32 PM, Dave Keck wrote:

I'm having a really hard time making sense of you message...

> I have been trying to implement a 1 second repeating timer, but its leading
> to retaining the target object


That's expected behavior - NSTimers retain their targets. The target won't be deallocated until the timer has been invalidated (assuming the timer was the only thing keeping the target alive.)

> But its leading to referencing the target object of my thread, by 3-4
> non-objects (bytes), which shows different descriptions every time as per GC
> Monitor Instrument (kind of undefined behavior).


Woah, this sentence has my completely baffled:

o Prior to this sentence, you were talking about retaining/ releasing, not you're talking about garbage collection. I think I'm still following you though - regardless, the timer is keeping the target alive.

 o 3-4 bytes of what? Why do these bytes matter?

========== Moment of clarity in 3... 2... 1...

Oh. I think you're just trying to have a method called every second. If that's the case, no need to concern yourself with threads and... well, whatever it is that's going on in that code snippet. :D

[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector(doSomething:) userInfo: nil repeats: YES];

That will call self's -doSomething: method every second. Is that what you're trying to accomplish?

_______________________________________________

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: to implement a 1 sec repeating timer in a separate thread
      • From: Dave Keck <email@hidden>
References: 
 >to implement a 1 sec repeating timer in a separate thread (From: Nick Rogers <email@hidden>)
 >Re: to implement a 1 sec repeating timer in a separate thread (From: Dave Keck <email@hidden>)

  • Prev by Date: Re: NSNotificationCentre very slow - normal?
  • Next by Date: Re: Search on Core data Table issue?
  • Previous by thread: Re: to implement a 1 sec repeating timer in a separate thread
  • Next by thread: Re: to implement a 1 sec repeating timer in a separate thread
  • Index(es):
    • Date
    • Thread