• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Memory and stringByAppendingString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Memory and stringByAppendingString (From: Aidas Dailide <email@hidden>)

  • Prev by Date: Re: Tracking Rect Obtuseness
  • Next by Date: Re: reading a text file
  • Previous by thread: Re: Memory and stringByAppendingString
  • Next by thread: Re: Memory and stringByAppendingString
  • Index(es):
    • Date
    • Thread