Re: literal strings - who do they belong to?
Re: literal strings - who do they belong to?
- Subject: Re: literal strings - who do they belong to?
- From: BJ Homer <email@hidden>
- Date: Mon, 13 Jul 2009 00:43:12 -0600
>
> 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 (email@hidden)
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:
This email sent to email@hidden