Re: Why my object becomes invalid ?
Re: Why my object becomes invalid ?
- Subject: Re: Why my object becomes invalid ?
- From: Chris Hanson <email@hidden>
- Date: Sat, 9 Aug 2003 00:45:20 -0500
On Friday, August 8, 2003, at 09:03 PM, Cameron Hayne wrote:
On 8/8/03 9:09 PM, "kubernan @ 10191 Tec." <email@hidden> wrote:
myString = [[NSString alloc] init];
myString = [myString stringByAppendingString:@"test"];
The variable 'myString' is a data member and hence must be retained.
Actually, "myString" is an instance variable. The object the instance
variable refers to may should be retained by its owner and anyone else
who needs a long-term reference to it. In other words, don't think of
variables "as" objects but as "referring to" objects.
I find that trying to keep the terminology strictly correct helps me
write better code, because it shapes how I think about things. This
applies for any number of techniques and technologies.
Thus your original, nicely
allocaed string object is no longer in the picture. After the second
line,
mystring is pointing at the object that was alloacted by
stringByAppendingString and that object will be autoreleased. So it
goes
away after this method returns.
This is absolutely correct, as is the rest of your posting.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.