I am referring to locations 2325 & 2340, Kindle version - when you are trying to explain how 2 objects have strong references to each other.
The code on these pages are as follows:
//location 2325 BNRItem *backpack = [[BNRItem alloc] init] [backpack setItemName:@"Backpack"]; [items addObject]; BNRItem *calculator = [[BNRItem alloc] init]; [calculator setItemName:@"Calculator"]; [items addObject:calculator]; [backpack setContainedItem:calculator]; //location 2340 NSLog(@"Setting items to nil..."); items = nil;
So according to the material, the backpack instance variable BNRItem * points to the address of the calculator BNRItem * but the calculator pointer doesn’t point back to the backpack pointer(if it does, I dont see where that is happening since all you are doing is making the local BNRItem * of backpack point to the Calculator BNRItem *). That is what i was confused about before i ran the program. Indeed to add to the confusion, both objects were destroyed which contradicts what the book says will happen - which is that the console will not report that the dealloc method was called and that the objects were destroyed.
If i were to add the line of code - like: [container setContainedItem], then dealloc is never executed and makes more sense - to me at least.
Was this a typo in the kindle version or is there something more sinister going on here? I am using Mountain Lion, XCode 4.5.1. The methods in the BNRItem class are set up correctly as I have double and triple checked. thanks!@