Skip to content

Instantly share code, notes, and snippets.

@threeve
Created April 23, 2011 04:47
Show Gist options
  • Save threeve/938302 to your computer and use it in GitHub Desktop.
Save threeve/938302 to your computer and use it in GitHub Desktop.
#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