我有两个弱的属性,声明如下:
@property (nonatomic, weak) NSString *weakProperty;
@property (nonatomic, weak) NSMutableString *weakMutableProperty;
- (void)testNonMutable
{
NSString *name = @"ABC";
self.weakProperty = name;
name = nil;
NSLog(@"Printing weak property %@",self.weakProperty);
}
- (void)testMutable
{
NSMutableString *name = [NSMutableString stringWithString:@"ABC"];
self.weakMutableProperty = name;
name = nil;
NSLog(@"Mutable : Printing weak property %@",self.weakMutableProperty);
}
我期待NSLog语句打印nil,但它在第一种方法中打印ABC。但它确实在第二种方法中。 有人可以帮助我吗?