Re: Inconsistent Memory Management Rules
Re: Inconsistent Memory Management Rules
- Subject: Re: Inconsistent Memory Management Rules
- From: alex <email@hidden>
- Date: Tue, 15 Apr 2003 13:32:07 -0700
Hi Denis,
string must have been declared somewhere else such as in the header. As
you can see it's nothing in the code you quoted, it's not even
dynamically typed as id and certainly without being declared somewhere
else wouldn't work at all the way quoted.
Alex
On Tuesday, April 15, 2003, at 01:04 PM, Denis Stanton wrote:
From: Denis Stanton <email@hidden>
Date: Tue Apr 15, 2003 1:04:18 PM US/Pacific
To: Lloyd Dupont <email@hidden>
Cc: Cocoa <email@hidden>
Subject: Re: Inconsistent Memory Management Rules
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.
_______________________________________________
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.