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

Re: autorelease question


  • Subject: Re: autorelease question
  • From: Matt Brindley <email@hidden>
  • Date: Fri, 05 May 2006 16:20:23 +0100

(I'm new to obj-c so i'm not sure how the mac does this, but for win dev):

The only downside to a timer is that it might not actually represent your interval. If you set a timer to trigger every 60 minutes, and start it on the hour - you'll find it falls behind pretty quickly. (Again, this might not actually be the case on the mac).

I find a stable way is to set the timer interval to a smaller amount, then check if the next task time has been exceeded. So have a timeWaitingFor var and check if the timeWaitingFor is greater than now.

Pseudo:

interval = 5 minutes
timeWaitingFor = "00:15:00"
...

OnTick()
{
    if (timeWaitingFor > Now)
   {
          timeWaitingFor += 15 minutes
          doTask()
   }
   else
   {
       // carry on waiting...
   }
}

You still can't be sure that it will run the task at the correct time, but you can be sure it won't fall more than 5 minutes (in this example) out of sync.

Bill Bumgarner wrote:
On May 5, 2006, at 7:10 AM, Jerrod Fowkes wrote:

I have a thread that runs continuously. In that thread I need to keep checking a time interval. If it has become 15 mintues or an hour then do some sort of operation. Well, currently I am trying to use NSCalendarDate. My main question is :

If I keep ' time = [NSCalendarDate calendarDate];' in a loop, will that flood the autorelease pool?

My other question is, Do you think this solution would be better handled with an NSTimer?

Yes. And it will manage a release pool for you. Actually, the busy-loop-and-test-a-calendar-data method is fatally flawed in that it uses CPU cycles when the thread isn't doing anything.


Never, ever, create software that does a busy wait....
_______________________________________________




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >autorelease question (From: Jerrod Fowkes <email@hidden>)
 >Re: autorelease question (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: autorelease question
  • Next by Date: Key-Value Coding Limitations
  • Previous by thread: Re: autorelease question
  • Next by thread: Re: autorelease question
  • Index(es):
    • Date
    • Thread