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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:03:26+00:00 2026-06-17T18:03:26+00:00

I have a method like this: – (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error { @autoreleasepool

  • 0

I have a method like this:

- (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error
{
    @autoreleasepool {

          // Start processing.

          // Find some partway through error..
          if (error) {
              *error = [NSError errorWithDomain...];
              return NO;
          }

          // More processing.
    }
}

This is broken and crashes, because the NSError is autoreleased, and when the return happens, the pool is drained, so the thing that the caller gets is now bogus.

I know I could significantly redesign the method so I collect all error cases outside the autorelease block, but I want to understand whether there’s a correct way of handling the error object in this situation. I can’t alloc/init a speculative NSError outside the pool block, because the domain and code properties are readonly (and I still think the reference would disappear when the method returns).

It solves the problem if I change the method declaration to this:

- (void)processAThing:(id)thing error:(NSError * __strong *)error

But then I need to fuss around at the call site in a nonstandard way, and this seems egregious to make the caller pay the price for my internal autoreleasepool.

Any thoughts? Thanks.

  • 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-17T18:03:27+00:00Added an answer on June 17, 2026 at 6:03 pm

    I had this problem myself. In this case, I think you just need to declare a new strong reference just before the @autoreleasepool, and set the method argument just after the @autoreleasepool block from that temporary reference.

    - (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error {
      __strong NSError *errOut = nil;
      @autoreleasepool {
        // do your stuff and set errOut instead of error
      }
      if (error) {
        *error = errOut;
      }
    }
    

    (typed in browser, not error checked by compiler)

    As for your premature return, I guess you’ll have to use a jump label (even if it’s not pretty).

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

Sidebar

Related Questions

If I have a method like this: public void DoSomething(int Count, string[] Lines) {
Suppose I have a method like this: public void MyCoolMethod(ref bool scannerEnabled) { try
I have a mapper method like this : @InsertProvider(class=com.something.class, method=doSomething) public void insertSomething(Set<Integer> set,
I have a method like this. - (void)loadData { RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@http://localhost:8080/activiti-rest/service];
When I have a method like this: public static void foo(String param) throws IOException
I have method like this: public static void Raise<TEvent>(TEvent eventToRaise) where TEvent : IEvent
I have a method like this that goes through an array to find different
I have a method like this: public void MyMethod(int p1, int p2) { //some
I have POST method like this public void PostMethod([FromBody]string param) { var test =
I have a method like this: public void getSomething(){ ... } I want to

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.