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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:21:46+00:00 2026-05-23T13:21:46+00:00

One of the patterns presented at the WWDC 2010 Blocks and Grand Central Dispatch

  • 0

One of the patterns presented at the WWDC 2010 “Blocks and Grand Central Dispatch” talk was to use nested dispatch_async calls to perform time consuming tasks on a background thread and then update the UI on the main thread once the task is complete

dispatch_async(backgroundQueue, ^{
    // do something time consuming in background
    NSArray *results = ComputeBigKnarlyThingThatWouldBlockForAWhile();

    // use results on the main thread
    dispatch_async(dispatch_get_main_queue(), ^{
        [myViewController UpdateUiWithResults:results];
    });
});

Since “myViewController” is being used inside the blocks, it automatically gets a ‘retain’ and will later get a ‘release’ when the blocks are cleaned up.

If the block’s ‘release’ call is the final release call (for example, the user navigates away from the view while the background task is running) the myViewController dealloc method is called — but it’s called on the background thread!!

UIKit objects do not like to be de-allocated outside of the main thread. In my case, UIWebView throws an exception.

How can this WWDC presented pattern – specifically mentioned as the best new way to avoid UI lockup – be so flawed? Am I missing something?

  • 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-23T13:21:46+00:00Added an answer on May 23, 2026 at 1:21 pm

    You can use the __block storage type qualifier for such a case. __block variables are not automatically retained by the block. So you need to retain the object by yourself:

    __block UIViewController *viewController = [myViewController retain];
    dispatch_async(backgroundQueue, ^{
        // Do long-running work here.
        dispatch_async(dispatch_get_main_queue(), ^{
            [viewController updateUIWithResults:results];
            [viewController release]; // Ensure it's released on main thread
        }
    });
    

    EDIT

    With ARC, __block variable object is automatically retained by the block, but we can set nil value to the __block variable for releasing the retained object whenever we want.

    __block UIViewController *viewController = myViewController;
    dispatch_async(backgroundQueue, ^{
        // Do long-running work here.
        dispatch_async(dispatch_get_main_queue(), ^{
            [viewController updateUIWithResults:results];
            viewController = nil; // Ensure it's released on main thread
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use the Composite pattern for forwarding calls received by one object
One of the patterns that I frequently run across when developing is trying to
I've been using grep -f to obtain patterns from one file and extract lines
Is there a way to obtain patterns in one file (a list of patterns)
I try to draw a sequence of pattern images (different repeated patterns in one
Are there any known design principles, best-practices and design patterns that one can follow
I have the following patterns and grouping application which I am refactoring in one.
I've been trying to figure this one out for a bit using patterns or
Usually I make my Regex patterns by myself, but I can't figure this one
I am conditionally using two different url patterns, mean on one URL I am

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.