Reputation: 8131
This my snippet:
Foo *myFooOne = [[Foo alloc] initWithName:@"my string"];
Foo *myFooTwo = myFooOne;
[myFooOne release];
NSLog(@"Name: %@", myFooTwo.name);
why myFooTwo.name
produce correctly output, instead of a runtime error
?
2011-10-28 14:45:10.718 Example[6410:f803] Name: my string
thanks.
Upvotes: 1
Views: 82
Reputation: 5237
When you release the Foo object, it's previously allocated memory is freed, but that does not necessarily mean that the data in that memory block is 'cleared'. In this case the myFooTwo pointer is still pointing at valid Foo data.
This could not always be the case.
Upvotes: 1
Reputation: 78845
You are just lucky that the released memory hasn't been reused for something else and been overwritten. Otherwise, it would fail.
Run you app with NSZombieEnabled set to YES and it should raise an error at run-time.
Upvotes: 4