Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3809198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:16:05+00:00 2026-05-19T15:16:05+00:00

I just ran into a weird behaviour with NSOperation that I fixed but do

  • 0

I just ran into a weird behaviour with NSOperation that I fixed but do not understand.

I subclassed NSOperation by following the documentation. When I use the main method below, the application will use 100% or more of the CPU time.

-(void)main 
{
    @try 
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

        //Cycle forever until told to cancel
        while (![self isCancelled])
        {

        }

        [pool release];
    }
    @catch(...) 
    {
        // Do not rethrow exceptions.
    }

    //Finish executing
    [self completeOperation]; //Send notificatios using KVO
}

Conversely when I use the following main method, the application uses 3% of the CPU time.

-(void)main 
{
    @try 
    {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

        //Create the initial delayed timers
        NSTimer *startUpTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];

        NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
        [runLoop addTimer:startUpTimer forMode:NSRunLoopCommonModes];
        [runLoop run];

        //Cycle forever until told to cancel
        while (![self isCancelled])
        {

        }

        [pool release];
    }
    @catch(...) 
    {
        // Do not rethrow exceptions.
    }

    //Finish executing
    [self completeOperation]; //Send notificatios using KVO
}

This strange behaviour appears to be attributed to the timer. If the timer is asked to not repeat itself, the application uses 100% CPU time, but if the timer is asked to repeat itself, then the CPU usage is normal.

It appears that when nothing is running on the thread, the CPU usage is really high (I would assume it would be the opposite). Any suggestions on why this is the case?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:16:06+00:00Added an answer on May 19, 2026 at 3:16 pm

    Cycling a while loop will take 100% of a single core of a CPU. This is what a loop does, regardless of being in a queue or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran into the weirdest of bugs today. I'm not sure if it's
Just ran into this recently and I thought it'd be helpful to share. The
Just ran into UX problem to save UITextField input value.I've got 6 UItextfield entries
I just ran into what seems like absurd behavior to me. If IE8 doesn't
Hi I just ran into a sync problem, and have replicated it in this
I'm just started using SQL and ran into a problem. In my database, I
While fiddling around to try to automate some process, I ran into this seemingly
I'm running celeryd as a daemon, but I sometimes have trouble stopping it gracefully.
all. I'm currently working with an old established code base for a new project
I'm failing a bit to get this working. I read out a date from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.