Created
January 5, 2020 17:44
-
-
Save bdash/2105ae0c7039c5d77aee82d8df385738 to your computer and use it in GitHub Desktop.
Demonstrate a case of a spurious warning about an instance being immediately deallocated
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 RetainCycle : NSObject | |
@end | |
@implementation RetainCycle { | |
id _object; | |
} | |
- (instancetype)init { | |
if (!(self = [super init])) { | |
return nil; | |
} | |
_object = self; | |
return self; | |
} | |
- (void)dealloc { | |
NSLog(@"-[%@ dealloc]", self); | |
} | |
- (void)breakCycle { | |
_object = nil; | |
} | |
@end | |
int main(int argc, char** argv) { | |
__weak RetainCycle *weak = [[RetainCycle alloc] init]; | |
NSLog(@"weak: %@", weak); | |
[weak breakCycle]; | |
NSLog(@"weak: %@", weak); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment