When does a weak reference get updated to nil in Objective-C? [duplicate]
问题 This question already has answers here : Why isn’t my weak reference cleared right after the strong ones are gone? (4 answers) Closed 6 years ago . Consider the following two cases: // case 1 NSObject *strongOne = [[NSObject alloc] init]; NSObject * __weak weakOne = strongOne; if (weakOne) { NSLog(@"weakOne is not nil."); } else { NSLog(@"weakOne is nil."); } strongOne = nil; if (weakOne) { NSLog(@"weakOne is not nil."); } else { NSLog(@"weakOne is nil."); } Outputs this: weakOne is not nil.