Re: Memory and stringByAppendingString
Re: Memory and stringByAppendingString
- Subject: Re: Memory and stringByAppendingString
- From: publiclook <email@hidden>
- Date: Sun, 18 May 2003 17:31:03 -0400
On Sunday, May 18, 2003, at 03:56 PM, Aidas Dailide wrote:
Hi,
I have a question about memory management. I still can't master it. I
just can't fully understand what to do on some case. Here is one of
them:
The following line is crazy. It could just be NSString *finalH = @" ";
NSString* finalH=[[[[NSString alloc] initWithString:@""]
autorelease] retain];
How about this instead
NSMutableString *finalH = [[NSMutableString alloc] init];
for(i = 0; i < [array count];i++)
{
[finalH appendFormat:@"%@ ", [self hyphenateString:[array
objectAtIndex:i]]];
}
for (i=0;i<[array count];i++)
{
finalH=[finalH stringByAppendingString:[self
hyphenateString:[array objectAtIndex:i]]];
finalH=[finalH stringByAppendingString:@" "];
}
If for some reason you don't want to use mutable strings:
NSString *finalH = @" ";
for(i = 0; i < [array count];i++)
{
NSAutoreleasePool localPool = [[NSAutoreleasePool alloc] init];
finalH = [finalH stringByAppendingString:[self
hyphenateString:[array objectAtIndex:i]]];
finalH = [finalH stringByAppendingString:@" "];
[localPool release];
}
or
NSString *finalH = @" ";
for(i = 0; i < [array count];i++)
{
NSString *temp = [[NSString alloc] initWithFormat:@"%@%@ ",
finalH, [self hyphenateString:[array objectAtIndex:i]]];
[finalH release];
finalH = temp;
}
_______________________________________________
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.