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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:50:14+00:00 2026-06-18T03:50:14+00:00

After [block copy] and executed block(); , should I set block=nil ? Or does

  • 0

After [block copy] and executed block();, should I set block=nil? Or does ARC already manage this for me so I don’t have to do anything?
I’m a bit confused on how ARC manages block references here and I’m not sure setting the block to nil would break anything or not?

I have something like this. Any thoughts?

typedef void (^C3Block)(void);    // declare block, no return, no args

// set flag to get _previewImage, then call the block
- (void)takePreviewImageFromBufferWithBlock:(C3Block)block {
    _takePreviewImageBlock = [block copy]; // save block ref for calling later
    _shouldTakePreviewImageFromBuffer = YES;
}

- (void)gotPreviewImageFromBuffer {
    _takePreviewImageBlock(); // calls the block
    _takePreviewImageBlock = nil; // <---- should I do this???
}
  • 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-06-18T03:50:15+00:00Added an answer on June 18, 2026 at 3:50 am

    I think it’s a good idea to set it to nil, and here is why:

    Let’s call the class these methods are in ImageLoader. Suppose I have a class MyViewController that has a strong reference to this ImageLoader (it’s an instance variable, say), and passes it a block that retains self (i.e. the MyViewController). Why does it retain self? Well, your ImageLoader presumably works asynchronously, so, say, I want my MyViewController to be around long enough to handle the response.

    Okay, so we have a retain cycle. The MyViewController retains the ImageLoader, which retains the block, which retains the MyViewController. However, if you simply nil the block variable at the end of the operation in ImageLoader, it will break this cycle. Otherwise these objects will never be deallocated. It kind of makes sense for ImageLoader to set the block variable to nil when its operation is done because it no longer “needs” it.

    (You could also argue that the issue in the scenario above could be avoided by arranging the retains differently — that MyViewController should not retain ImageLoader. Then, during the asynchronous operation, ImageLoader must still be retained by something from the ongoing operation. ImageLoader still retains the block which retains MyViewController. When the operation is done, the operation releasing ImageLoader will release everything, and everyone is happy, without needing to set the block variable to nil.)

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

Sidebar

Related Questions

Is it possible to have one jQuery ready block executed after all others have
Let's say I have cleaner like this .cleaner:after { content: '.'; display: block; clear:
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I have these links : Block 1 : <a href=/Products?dep=56&cat=252&tab=2>Adapters</a> <a href=/Products?dep=58&cat=654&tab=2>Battery</a> After click
Assignments (i.e. set statements) made within an if block are not realized until after
I have some code where I frequently copy a large block of memory, often
I don't really know when do I need to copy a block. The documentation
I try to use sed to insert a line after [Block B] in the
I am currently using two catch blocks after a try block. The first catches
I'm trying to use jQuery.scrollTo plugin with accordion (where one block expands after clicking

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.