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

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

  • Prev by Date: Memory and stringByAppendingString
  • Next by Date: Re: [BUG] NSSelectorFromString Sometimes Lies
  • Previous by thread: Memory and stringByAppendingString
  • Next by thread: Re: Memory and stringByAppendingString
  • Index(es):
    • Date
    • Thread