Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to release a returned NSError object?

There are many Cocoa methods that require an NSError object as a parameter to a method, but are really a means of returning an error object to the calling method if errors exist. Is this returned object retained? That is, in the calling object code (the method to which the error is returned), does there need to be some code like:

  NSError *error;
  [apiCall .... error:&error];

  if (error){
    [*error release];
 }

I haven't seen this anywhere, and if it does need to be released, is this the way to do it?

like image 378
casademora Avatar asked Oct 29 '09 02:10

casademora


1 Answers

Returned objects are generally autoreleased. The general rule is you only call auto-/release if you earlier called copy/alloc/retain on the same object. And you wouldn't dereference error in a method call:

// right
[error code]
// wrong
[*error code]
like image 72
outis Avatar answered Nov 11 '22 04:11

outis