Skip to content

Instantly share code, notes, and snippets.

@alaborie
Created June 15, 2012 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaborie/2938856 to your computer and use it in GitHub Desktop.
Save alaborie/2938856 to your computer and use it in GitHub Desktop.
enumerateObjectsUsingBlock nested in an autorelease pool?
NSError *error = nil;
void (^block)(NSError **error);
block = ^(NSError **blockError)
{
NSArray *array = [NSArray arrayWithObject:@"hello"];
[array enumerateObjectsUsingBlock:^(id object, NSUInteger index, BOOL *stop) {
if ( blockError != NULL )
{
*blockError = [NSError errorWithDomain:@"domain" code:0 userInfo:nil];
*stop = YES;
}
}];
};
block(&error);
if ( error != nil )
{
[error retain];
}
@alaborie
Copy link
Author

If you enable the zombies the code will crash at line 19. Apparently the NSError is released when leaving the enumeration block of the array. So the enumeration is probably done within an autorelease block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment