zuccoi/REKit — pull request #6 by bounin (2013-03-07 01:40:46+00:00)
Title: Keep reference to implementation pointer in blockInfo instead of block itself to fix block retaining leak

Synopsis:
Check strong referenced object inside block and it is never released:
AnyClass * obj = [AnyClass new]
[alertView respondsToSelector:@selector(alertView:didDismissWithButtonIndex:) withKey:nil usingBlock:^(id receiver, UIAlertView *alertView, NSInteger buttonIndex) {
//// to capture obj
NSLog (@"%@", obj);
}];

Problem:
imp_implementationWithBlock() retains block so expression 'imp_removeBlock(imp_implementationWithBlock(block))' just keeps retaining count by retaining and releasing block. (CFRetainCount always returns 1 for block objects). Similar you create extra reference for every superblock when you call (imp_implementationWithBlock(block) in supermethodOfCurrentBlock method

Solution:
It is better to keep created block implementation pointer in blockInfo dictionary instead of block itself. And use it later when releasing or returning superblock implementation.

After you apply new implementation obj variable from code above released after alertView disappears and released.