Created
August 5, 2011 00:14
-
-
Save ccgus/1126639 to your computer and use it in GitHub Desktop.
Weak Sauce
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 FMFancyObject : NSObject { | |
} | |
@end | |
@interface FMDeallocCheckerObjectHolder : NSObject { | |
__weak id _holdingObject; | |
} | |
@property (weak) id holdingObject; | |
@end | |
@implementation FMDeallocCheckerObjectHolder | |
@synthesize holdingObject=_holdingObject; | |
@end | |
@implementation FMFancyObject | |
- (void)dealloc { | |
NSLog(@"FMFancyObject dealloc!"); | |
[super dealloc]; | |
} | |
@end | |
int main (int argc, const char * argv[]) { | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
FMDeallocCheckerObjectHolder *objh = [FMDeallocCheckerObjectHolder new]; | |
FMFancyObject *foo = [FMFancyObject new]; | |
[objh setHoldingObject:foo]; | |
NSLog(@"Releasing…"); | |
[foo release]; | |
NSLog(@"Released!"); | |
if ([objh holdingObject]) { | |
NSLog(@"wait, what? you should not be seeing this line"); | |
} | |
[objh release]; | |
[pool drain]; | |
return 0; | |
} | |
/* | |
2011-08-04 17:12:55.863 weaksauce[31567:1307] Releasing… | |
2011-08-04 17:12:55.866 weaksauce[31567:1307] FMFancyObject dealloc! | |
2011-08-04 17:12:55.867 weaksauce[31567:1307] Released! | |
2011-08-04 17:12:55.868 weaksauce[31567:1307] wait, what? you should not be seeing this line | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment