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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:26:22+00:00 2026-06-18T00:26:22+00:00

As per Transitioning to ARC Release Notes : __autoreleasing is used to denote arguments

  • 0

As per Transitioning to ARC Release Notes:

__autoreleasing is used to denote arguments that are passed by reference (id *) and are autoreleased on return.

For example:

-(BOOL)performOperationWithError:(NSError * __autoreleasing *)error;

But what are the advantages of the above comparing to:

-(BOOL)performOperationWithError:(NSError * __strong *)error;


Update:

Several answers refer to the temp var trick compiler does to deal with the mismatch between var and argument as the advantage of __autoreleasing. I don’t see why compiler can not do the same trick for __strong argument. I mean, for a __weak var and __strong argument, compiler can similarly do this:

NSError * __weak error;
NSError * __strong tmp = error;
BOOL OK = [myObject performOperationWithError:&tmp];
error = tmp;
if (!OK) {
    // Report the error.
}

Compiler knows -(BOOL)performOperationWithError:(NSError * __strong *)error; returns a strong reference(+1) so it handles it just like any new-family method. Since tmp lives in the same scope as error, compiler can reasonably keep it alive as long as error so the __weak reference(error) is now supported by a __strong reference(tmp) and will not be nullified until the end of the scope.

  • 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-18T00:26:23+00:00Added an answer on June 18, 2026 at 12:26 am

    tl;dr

    Implicitly converting a __weak object to a __strong object in this case would alter the semantic of the program, something that a compiler should never do.


    The scenario

    Let’s take an example

    NSError *error;
    BOOL success = [myObject performOperationWithError:&error];
    if (!success) {
        // Report the error
    }
    

    In such a case the error local variable is automatically inferred by ARC as __strong.

    At the same time the error argument of

    -(BOOL)performOperationWithError:(NSError * __autoreleasing *)error;
    

    is of type NSError * __autoreleasing *.

    Please note that in any case ARC will infer parameters passed by reference (id *) as being of type id __autoreleasing *, so the above signature is equivalent to

    -(BOOL)performOperationWithError:(NSError **)error;
    

    under ARC.

    Therefore we have a mismatch since we are passing a __strong annotated variable to a method expecting an __autoreleasing argument.

    Under the hood

    In our example then the compiler will address such mismatch by creating a local __autoreleasing tmp variable.

    The code becomes

    NSError * __strong error;
    NSError * __autoreleasing tmp = error;
    BOOL success = [myObject performOperationWithError:&tmp];
    error = tmp;
    if (!success) {
        // Report the error.
    }
    

    An alternative

    Let’s now pretend that we can change the signature of performOperationWithError:.

    If we want to avoid the "compiler trick" which uses the tmp variable, we can declare our signature as

    -(BOOL)performOperationWithError:(NSError * __strong *)error;
    

    We have a __strong variable and we are now passing it to a method expecting a __strong argument, so we just eliminated the mismatch.

    Looks good, why not always declare __strong arguments?

    One reason is that declaring the argument as __autoreleasing will make the method to accept even a __weak reference.

    It does not make much sense in the current example, but there could be cases in which we’d like to pass a __weak variable by reference and declaring __autoreleasing (or leaving the ARC to infer it) will allow us to do so.

    ARC will apply the same trick seen above, creating a __autoreleasing tmp variable.

    Conclusion

    The mechanism presented so far goes under the name of pass-by-writeback.

    Such mechanism has been designed to work with __autoreleasing, __strong and __weak variables, so that the programmer can safely rely on the type inference made by the compiler and not care too much about annotating variables around.

    Declaring a id __strong * argument may make sense in some cases, but in general it could lead to unexpected errors generated by the compiler.

    My advice here is: "let the compiler do his magic and you’ll be good"

    Update

    I don’t see why compiler can not do the same trick for __strong argument.

    Telling the compiler to handle in an __autoreleasing fashion the management of either a __strong or __weak variable it’s ok since it basically means: "Please, compiler, do the right thing automatically".

    That’s why the trick seen above will work without issues.

    On the other hand, if you declare a variable as __weak you presumably have a good reason for doing so and the last thing you want is to have it implicitly retained when you clearly specified otherwise. That would radically change the semantic of the piece of code you’ve written, therefore the compiler won’t do that (thank God!).

    In other words

    __weak –> __autoreleasing good
    __strong –> __autoreleasing good
    __weak <–> __strong wrong!

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

Sidebar

Related Questions

Per a client's request I have written a communication class that inherits from webclient.
Per http://perldoc.perl.org/CGI.html to make meta tags, the following example is given: print start_html(-head=>meta({-http_equiv =>
per my client request I have been requested to return a dataset. basically it's
Per-frame I need to allocate some data that needs to stick around until the
Per the javadoc: Indicates that the given @WebMethod has only an input message and
As per an example URL shortened here: http://goo.gl/info/kW1c#week What is the displayed 2D barcode
Per the MSDN documentation , the following syntax is used: // A read-write instance
Per the Go tour page 28 and page 53 They show a variable that
As per Shanes excellent solution of another question, I now realise that I do
As per the title, it seems only Chrome isn't playign along. Note that form

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.