3

Possible Duplicate:
In which situations do we need to write the __autoreleasing ownership qualifier under ARC?

making this method in the interface:

- (NSArray *)questionsFromJSON:(NSString *)jsonString 
                     withError:(NSError **)error;

when tabbing out autocomplete in the implementation it's adding this:

- (NSArray *)questionsFromJSON:(NSString *)jsonString withError:(NSError *__autoreleasing *)error

I figured with ARC there never needs to be the use of autorelease but I'm guessing this is different, as it compiles fine with ARC.

Just curious :)

Community
  • 1
  • 1
Mark W
  • 3,879
  • 2
  • 37
  • 53

1 Answers1

1

Autorelease is used a lot in ARC. You just don't see the keyword sprinkled around all over the place.

The example you site, is when you send a pointer to an object pointer, like the typical error scenario...

NSError *error = nil; if (![foo bar:&error]) {
    // handle error
}

Note, that the bar method will be doing something like...

- (void)bar:(NSError **errorPtr) {
    // blah...
    if (an_error_happened) {
        NSError *error = [NSError muckityMuck];
        *errorPtr = error;
    }
}

Now, the error object has been allocated, and "returned" like an autorelease from a function call. When you declare s function/method to take "**" you are implicitly stating __autorelease.

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87