Created
January 11, 2012 01:53
-
-
Save evanlong/1592478 to your computer and use it in GitHub Desktop.
Intead of ARC
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
Instead of ARC: | |
Add scoperelease in addition to release and autorelease. | |
Think of it like scoped_ptr in C++ or more generally how deconstructors | |
get called for stack allocated objects (end of scope). | |
- (id)someMethod:(NSInteger)n { | |
MyObject *o = [[[MyObject alloc] init] scoperelease]; | |
NSMutableString *s = [[[NSMutableString alloc] init] scoperelease]; | |
if (n < 0) { | |
return nil; | |
// compiler would insert [o release]; [s release]; | |
} | |
/// do some work on s here | |
return [NSNumber numberWithInteger:[s length]]; | |
// compiler would insert [o release]; [s release]; | |
} | |
Other changes: | |
Properties have two more options: deallocable, viewUnloadable (yes, some | |
terse names would be nice here) | |
In the header we would have: | |
@property (nonatomic, retain, deallocable, viewUnloadable) UIButton *button; | |
And in the implementation file: | |
@synthesize button; | |
Because the property is deallocable the a [button release] will be | |
inserted into the dealloc. | |
Because the property is viewUnloadable [button release]; button=nil | |
will be inserted into the viewDidUnload of a UIViewController. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment