Skip to content

Instantly share code, notes, and snippets.

@akio0911
Created May 14, 2009 03:45
Show Gist options
  • Save akio0911/111467 to your computer and use it in GitHub Desktop.
Save akio0911/111467 to your computer and use it in GitHub Desktop.
#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