Re: Inconsistent Memory Management Rules
Re: Inconsistent Memory Management Rules
- Subject: Re: Inconsistent Memory Management Rules
- From: Denis Stanton <email@hidden>
- Date: Wed, 16 Apr 2003 08:04:18 +1200
I have been following this thread and trying to learn a bit. I think I
have made most of the errors referred to. I'm gaining some
understanding and I can spot some of the errors, but I'm still a bit
confused. Can you explain one item a bit more please?
On Monday, April 14, 2003, at 04:05 PM, Lloyd Dupont wrote:
first your code is full of error, no worries I will teach you !
NSString * string = [[NSString alloc] init]; // what do you want to
do with an unmutable empty string ?
string = [string stringByAppendingString:@"Lloyd Dupont]; // this one
is very bad, what about the previous value ?
instead use
string = [[string autorelease] stringByAppendingString:@"Lloyd Dupont];
I understand the comments pointing out the errors in the first example,
but I am surprised that the alternative offered does the job.
string = [[string autorelease] stringByAppendingString:@"Lloyd Dupont];
There is no type declaration for "string" here. How does the complier
know what "string" is? In the incorrect example the part statement
NSString *string ......
tells the compiler that string is an NSString. In the second example
it uses and object [string autorelease] without previously declaring it
This is still confusing for me.
On reading the example again I wonder if your suggested line was only
meant to replace line 2 of the original, keeping line 1, the allocation
of string. In this case your original criticism of line 1 "what do
you want to do with an unmutable empty string ?" would still hold.
Denis
_______________________________________________
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.