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 6076659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:37:59+00:00 2026-05-23T10:37:59+00:00

I have a strange error which pop up recently. The NSOperationQueue says it has

  • 0

I have a strange error which pop up recently. The NSOperationQueue says it has 1 object in it however I cannot access the NSOperation object inside it.

    if ([[queue operations] count] > 0)
    op = [queue.operations objectAtIndex:0];

But for some reason it ends up in the following exception: index 0 beyond bounds for empty array’

I understand the error message however I am surprised since I was checking the queue count before asking for the object itself.

Any ideas please?

  • 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-23T10:38:00+00:00Added an answer on May 23, 2026 at 10:38 am

    Remember that operations are able to run on separate threads and usually are. An NSOperationQueue actually has its own method for getting the count called operationCount and provides this word of caution:

    The value returned by this method
    reflects the instantaneous number of
    objects in the queue and changes as
    operations are completed. As a result,
    by the time you use the returned
    value, the actual number of operations
    may be different. You should therefore
    use this value only for approximate
    guidance and should not rely on it for
    object enumerations or other precise
    calculations.

    What you are running into is probably a concurrency issue. One thing to consider is to copy the operations array.

    NSArray *ops = [queue.operations copy];
    if ([ops count] > 0)
    {
        op = [ops objectAtIndex:0];
        //You can check if it has finished using [op isFinished];
        //and do what you need to do here
    }
    [ops release];
    

    Update:

    Here is an example of why you may see this happening very often

    //Set up and start an NSOperation
    ...
    
    //Here your call to operations probably put some sort of lock
    //around operations to retrieve them but your operation also
    //finished and is waiting for your lock to complete to remove
    //the operation. The operations call probably returns a copy.
    if([[que operations] count] > 0)
    {
        //Now the operation queue can access its operations and remove
        //the item with the lock released (it can actually access as early
        //as before the call and count)
    
        //Uh oh now there are 0 operations
        op = [queue.operations objectAtIndex:0];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange error in my app, which says: * Terminating app due
I have a strange error. I have a page which loads values according to
We have a very strange error occurring at a developer site which we are
When compiling code which uses code contracts, I have a very strange error I
I have a strange error where my jquery ajax request doesn't submit all the
I am getting a strange error using jQuery 1.3.2 and Firefox. I have created
I have an application where every now and then I'm getting a strange error.
it is very strange, because this error doesn't happen all the time... I have
I'm getting a strange error. I have a function of the following signature: template
i got a compile error which i do not understand. i have a h/cpp

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.