0

I have 2 properties that are weak, declared as follows :

@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);
}

I was expecting the NSLog statement to print nil , but it prints ABC in the first method. However it does in the second method. Can someone please help me ?

Preetham Baliga
  • 271
  • 2
  • 4
  • 15

0 Answers0