typedef void (^SimpleBlock)(void);

@interface MyBlockTest : NSObject
{
   NSMutableArray *things;
}

- (void)runMemoryTest;
- (SimpleBlock)makeBlock;

@end

@implementation MyBlockTest

- (id)init
{
   if ((self = [super init])) {
      things = [[NSMutableArray alloc] init];
      NSLog(@"1) Wartość licznika retain count: %i", [self retainCount]);
   }
   return self;
}

- (SimpleBlock)makeBlock
{
   __block MyBlockTest *mySelf = self;
   SimpleBlock block = ^{
      [things addObject:@"Mr. Horse"];
      NSLog(@"2) Wartość licznika retain count: %i", [mySelf retainCount]);
   };
   return Block_copy(block);
}

- (void)dealloc
{
   [things release];
   [super dealloc];
}

- (void)runMemoryTest
{
   SimpleBlock block = [self makeBlock];
   block();
   Block_release(block);
   NSLog(@"3) Wartość licznika retain count: %i", [self retainCount]); 
}

@end
