Created
January 8, 2013 23:51
-
-
Save Coneko/4489195 to your computer and use it in GitHub Desktop.
Testing -[RACScheduler scheduleRecursiveBlock:]'s memory consumption.
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> | |
#import <ReactiveCocoa/ReactiveCocoa.h> | |
@interface CountUpToXEnumerator : NSEnumerator | |
+ (instancetype)countUpTo:(NSUInteger)x; | |
@end | |
@implementation CountUpToXEnumerator { | |
NSUInteger _x; | |
NSUInteger _current; | |
} | |
+ (instancetype)countUpTo:(NSUInteger)x { | |
CountUpToXEnumerator *enumerator = [[self alloc] init]; | |
enumerator->_x = x; | |
return enumerator; | |
} | |
- (id)nextObject { | |
if (_current == _x) return nil; | |
return @(_current++); | |
} | |
@end | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSEnumerator *enumerator = [CountUpToXEnumerator countUpTo:1000000]; | |
__block NSUInteger sum = 0; | |
[[RACScheduler scheduler] scheduleRecursiveBlock:^(void (^reschedule)(void)) { | |
@autoreleasepool { | |
NSNumber *nextNumber __attribute__((objc_precise_lifetime)) = [enumerator nextObject]; | |
sum += nextNumber.unsignedIntegerValue; | |
} | |
reschedule(); | |
}]; | |
} | |
sleep(UINT32_MAX); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment