I have a way like this:
- (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error { @autoreleasepool {
This is broken and crashing because NSError is auto-implemented, and when the return occurs, the pool merges, so the thing that the caller receives is now fictitious.
I know that I can substantially redesign the method to collect all cases of errors outside the autorun block, but I want to understand if there is a correct way to handle the error object in this situation. I cannot select / fire a speculative NSError outside the pool block because the domain and code properties are readonly (and I still think the link will 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 about the call site in a non-standard way, and it seems egregious to make the subscriber pay the price for my internal autoreleasepool.
Any thoughts? Thanks.
ios objective-c automatic-ref-counting autorelease
Ben zotto
source share