• 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: 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.

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

  • Prev by Date: Window close notification
  • Next by Date: Re: Speed Traps
  • Previous by thread: Re: Memory and stringByAppendingString
  • Next by thread: Calling C++ library and/or framework from Obj C
  • Index(es):
    • Date
    • Thread