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?
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With