Re: Memory and stringByAppendingString
Re: Memory and stringByAppendingString
- Subject: Re: Memory and stringByAppendingString
- From: Just van Rossum <email@hidden>
- Date: Sun, 18 May 2003 22:10:51 +0200
Aidas Dailide wrote:
>
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:
>
NSString* finalH=[[[[NSString alloc] initWithString:@""]
autorelease]
>
retain];
>
for (i=0;i<[array count];i++)
>
{
>
finalH=[finalH stringByAppendingString:[self
>
hyphenateString:[array objectAtIndex:i]]];
>
finalH=[finalH stringByAppendingString:@" "];
>
}
>
>
Can you believe that this code can take about 100 Mb (ofcourse you
>
can)!! Could anyone explain me (and write some example code) on how to
>
fix this?
You're creating many temporary autoreleased objects that will only be
released _after_ your method is finished. I think you're better off with
an NSMutableString.
Just
_______________________________________________
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.