Retain cycle p71: NSLog influences deletion of object?


#1

I found this very strange behaviour when I was experimenting with the code on p71.

I added the same NSLog statement just before backpack was set to nil:

[code] BNRItem *backpack = [[BNRItem alloc] init];
[backpack setItemName:@“Backpack”];

    BNRItem *calculator = [[BNRItem alloc] init];
    [calculator setItemName:@"Calculator"];

    [backpack setContainedItem:calculator];
    NSLog(@"Container (before): %@", [calculator container]);
    
    backpack = nil;
    
    NSLog(@"Container (after): %@", [calculator container]);
    
    calculator = nil;

[/code]

To my big surprise when I ran the program, the second NSLog statement showed the container info just as if backpack still existed. When I outcomment the first NSLog the program works like expected.

Am I overseeing something? To my understanding this is incorrect behaviour. Thanks for your help.