by pashields · 15y ago · 0 comments
My problem with this argument is that the user could botch release just as well. Maybe they are slightly more likely to botch the setter, but either way they are botching it.
Since your object is likely to be dealloced at an odd time (for instance when an autorelease pool is drained), and in an inconsistent state (half its fields missing), it's much better to do a release.
- (void)dealloc {
self.someOtherVariable = nil;
self.myC = nil; // Sends KVO on myC. B sees half-deconstructed A.
self.myB = nil; // myB now is dealloc'd and stops observing A.
[super dealloc];
}
Admittedly this is a real edge case and probably bad design, but it's not overtly terrible. I have a couple cases where objects observe their owners.BTW thanks for the blog, Mike! I love it.
There may well be similar setups which aren't broken which still exhibit the problem, though.
Glad you enjoy the blog!