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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:52:42+00:00 2026-05-12T05:52:42+00:00

The run loop for the secondary thread of my application is below. It has

  • 0

The run loop for the secondary thread of my application is below.
It has a nested control loops.

  • The outer loop runs for the duration of the application
  • The inner loop runs while one view is open, then the thread waits while the view is not open.
  • Passes through the inner loop are short, a fraction of a second.

My code does not knowingly leave any autoreleased objects in unreleased pools, but I do not know what the OS is doing.

In the main thread, cocoa wraps an autorelease pool around every pass through the run loop.
In this secondary thread, I believe the closest equivalent is a pass through the inner loop.

The inner autorelease pool wraps each pass through the inner loop.

The middle pool wrap around the inner loop, so that objects created and autoreleased at this level are not held until the application terminates.

the outer pool wraps the whole runloop.

How can i determine what effect the creation and release of all these pools is having on the speed of my code.
How can I determine whether all three pools are necessary or overkill?

code and explanation:

- (void)processLoop
{

    NSAutoreleasePool * outerPool = [[NSAutoreleasePool alloc] init];
    [processCondition lock];

    //outer loop    
    //this loop runs until my application exits
    while (![[NSThread currentThread] isCancelled])    
    {
        NSAutoreleasePool *middlePool = [[NSAutoreleasePool alloc];
        if(processGo)
        {
            //inner loop
            //this loop runs typically for a few seconds
            while (processGo && ![[NSThread currentThread] isCancelled]) 
            {
                NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc]; init];
                //within inner loop
                //this takes a fraction of a second
                [self doSomething];
                [innerPool release];
            }
            [self tidyThingsUp];

        }
        else
        {
            [processCondition wait];
        } 
        [middlePool release];
    }
    [processCondition unlock];
    [outerPool release];
}

the combination of:

  • an inner while loop
  • NSCondition *processCondition
  • toggling processGo between YES and NO

allows me to stop and start the inner while loop without cancelling the thread.

if (processGo == YES)

execution enters the inner while loop.

When the main thread sets

processGo = NO

execution leaves the inner while loop and tidys up
on the next pass of the outer loop, execution hits

[processCondition wait]

and waits

if the the main thread resets

processGo == YES

and calls

[processCondition wait]

execution re-enters the inner loop

  • 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-12T05:52:43+00:00Added an answer on May 12, 2026 at 5:52 am

    I really can’t give too definitive an answer without knowing more about what some of those methods do, but the big concern when applying autorelease pools has to do with the number of objects each pool handles.

    There’s an interesting blog post out there that looks at the effect of additional autorelease pools on the creation and destruction of a million instances of NSObject. The gist of the post says that “autorelease pools are cheap”: the program continued to get more efficient with fewer objects per pool right up to somewhere around the 10 objects/1 pool ratio. (After that it skyrockets, because you’re closing in fast on creating a pool for every object, which is obviously silly.)

    The best thing for you to do is figure out roughly how many objects each release pool would be dealing with. For example, if your inner pool is handling a hundred objects each pass, and there are a hundred passes, getting rid of that pool would add ten thousand objects to the middle pool – this would be a Bad Thing. On the other hand, if the inner pool handles one object each pass for ten passes, then sure, go ahead and get rid of it.

    If you can’t make the decision, see if you can find a way to time the performance of just the inner loop or just the code executed within the scope of the middle pool, then add/remove autorelease pools as necessary. And remember: autorelease pools are cheap.

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

Sidebar

Related Questions

i have to run for loop on linux terminal itself how i can do.
If thread A sends a reference to an object to thread B, for example
I need to run a script (python) in App Engine for many times. One
I have a > x20000 loop in php that checks if an entry exists
I have a shell that runs where the preset env variables include: FOOCOUNT=4 FOO_0=John
Does UIView's -drawRect: method have to be drawn on the main thread or can
In an iPad app I'm developing, I need to put the network handling on
I want to send a large amount of data to a server using NSURLConnection
I've pretty much finished work on a white noise feature for one of my
First of all a statement: I'm a newbie when it comes to programming for

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.