NSString *myString = [NSString stringWithFormat:@"string1"];
__weak NSString *myString1 = myString;
myString= nil;
NSLog(@"%@, %@",myString,myString1);
I was expecting null , null
. But the output is string1, (null)
. Why is myString1 still holding the value as myString is set to nil?
Weak references only get zeroed when the object is deallocated. That object is not immediately deallocated (it's probably in an autorelease pool here, though there are many other reasons something might be held onto in different situations), so the reference stays alive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With