目标C中的弱属性

时间:2015-11-26 08:07:47

标签: ios objective-c memory memory-management weak-references

我有两个弱的属性,声明如下:

@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。但它确实在第二种方法中。 有人可以帮助我吗?

0 个答案:

没有答案