Last active
December 14, 2015 08:09
-
-
Save janodev/5055412 to your computer and use it in GitHub Desktop.
Leak-Free Recursive Blocks. See http://jeremywsherman.com/blog/2013/02/27/leak-free-recursive-blocks/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
// clang -framework Foundation main.m -o main && ./main | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSUInteger (^__block factorial)(NSUInteger n); | |
NSUInteger (^__block __weak weakFactorial)(NSUInteger n); | |
weakFactorial = factorial = ^ NSUInteger (NSUInteger n) { | |
return n==0 ? 1 : n * weakFactorial(n-1); | |
}; | |
NSLog(@"%ld",factorial(3)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment