Created
May 14, 2009 03:45
-
-
Save akio0911/111467 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 <Foundation/Foundation.h> | |
@interface ReferenceCounter : NSObject { | |
id obj; | |
} | |
- (void)setObj:(id)_obj; | |
@end | |
@implementation ReferenceCounter | |
- (void)setObj:(id)_obj { | |
obj = [_obj retain]; | |
} | |
- (void)dealloc { | |
[obj release]; | |
[super dealloc]; | |
} | |
@end | |
int main() { | |
id foo = [[NSObject alloc] init]; | |
NSLog(@"retainCount: %d", [foo retainCount]); | |
id rctest = [[ReferenceCounter alloc] init]; | |
[rctest setObj:foo]; | |
NSLog(@"retainCount: %d", [foo retainCount]); | |
[foo release]; | |
NSLog(@"retainCount: %d", [foo retainCount]); | |
[rctest release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment