Created
April 23, 2011 04:47
-
-
Save threeve/938302 to your computer and use it in GitHub Desktop.
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 "AutoAutoViewController.h" | |
#define RAScopeAutorelease() \ | |
NSAutoreleasePool *$ra_pool##__LINE__ __attribute__((cleanup($ra_scopeDrainAutoreleasePool))) = [NSAutoreleasePool ra_pool]; (void)$ra_pool##__LINE__ | |
void $ra_scopeDrainAutoreleasePool( NSAutoreleasePool **pool ) | |
{ | |
[*pool drain]; | |
} | |
@interface NSAutoreleasePool (RAHackityHack) | |
+ (NSAutoreleasePool*)ra_pool __attribute__((ns_returns_not_retained)); | |
@end | |
@implementation AutoAutoViewController | |
- (void) viewDidLoad; | |
{ | |
[super viewDidLoad]; | |
RAScopeAutorelease(); // magic | |
[NSString stringWithFormat:@"blarg"]; | |
// string release when leaving scope! | |
} | |
@end | |
@implementation NSAutoreleasePool (RAHackityHack) | |
+ (NSAutoreleasePool *) ra_pool; | |
{ | |
return [NSAutoreleasePool new]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment