if for example we have 2 object with an NSString property, one is weak and one is strong like this
@interface Class1 : NSObject
@property (weak) NSString *weakString;
@end
@interface Class2 : NSObject
@property (strong) NSString *strongString;
@end
then doing this:
NSString *string = [[NSString alloc] initWithString:@"bla"];
Class2 *c2 = [[Class2 alloc] init];
c2.strongString = string;
string = nil;
Class1 *c1 = [[Class1 alloc] init];
c1.weakString = c2.strongString;
c2.strongString = nil;
or even
c2 = nil;
and then what c1.weakString contains ?
assigning string to strongString call a retain on string, assigning string to nil send the first release to the string, assigning strongString to weakString doesn't change the retain count, then assigning nil to strongString send the second release to string or even assigning nil to c2, so releasing c2 should send the second release to string and so now the retainCount of weakString (and so string) should be zero and then released so weakString zeroed having nil if we try to access it
but 'weakString' still containing "bla" so the original string object, WHY?
nil. - user529758