> > But then I saw the case where I have an object which returns, as a method > result or a property, one of its instance variables. The caller holds on to > it (without retaining it) then releases (and deallocs) my object. My object > releases its instance variables which results in the caller holding a > reference to a dead value. > > { > Object *o = [Object new]; > NSString *s = o.somevalue; // gets o's instance variable > (without retain) > [o release]; // o's instance variable is released > NSLog(@"Crash: %@",s) // accesses dead string > } > > So, yes, the retain/autorelease isn't superfluous at all, though the usage > pattern that would trigger the problem seems relatively unlikely (in my > example, o seems far more likely to be autorelease'd). Is there a more > common case that I'm missing?
If o were in an NSDictionary that was passed to you in a parameter, for example, and you removed the key from the dictionary, you'd trigger the same problem. -BJ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com