Re: Memory and stringByAppendingString
Re: Memory and stringByAppendingString
- Subject: Re: Memory and stringByAppendingString
- From: Pete Yandell <email@hidden>
- Date: Mon, 19 May 2003 10:08:47 +1000
Whenever you do a stringByAppendingString: call you're creating a new
string which is a copy of your original string with something appended.
The original string still exists in the autorelease pool waiting to be
cleaned up at the next runloop.
A better way would be to use NSMutableString:
NSMutableString* finalH = [[NSMutableString alloc] init];
for (i = 0; i < [array count]; i++) {
[finalH appendFormat:"%@ ", [self hyphenateString:[array
objectAtIndex:i]]];
}
Note that you're still going to end up with some autoreleased strings
hanging around as (I'm assuming) hyphenateString: returns an
autoreleased string.
Also, from your original code:
NSString* finalH=[[[[NSString alloc] initWithString:@""]
autorelease] retain];
What the? I'm not sure what you're trying to do here. You could have
just as well used:
NSString* finalH = @"";
Pete Yandell
http://pete.yandell.com/
_______________________________________________
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.