• 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: NSMutableString question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableString question


  • Subject: Re: NSMutableString question
  • From: Dave DeLong <email@hidden>
  • Date: Tue, 16 Sep 2008 19:22:52 -0600

Earlier today I was experimenting with NSAutoreleasePools and built a little demo app. Basically it was two nested loops (the outer having 100 iterations, the inner 1000), and on each iteration of the inner loop, I created an autoreleased string (using stringWithFormat:).

I ran it twice. Once without any extra autorelease pools, and once with creating and draining a pool on each iteration of the outer loop. I ran it through Instruments and came up with this memory usage:

http://gallery.me.com/davedelong#100025/autoreleasing&bgcolor=black

The top graph shows how much memory the app was using for my strings without the extra pools, and the bottom one shows it with the extra two lines to instantiate and then drain the pool. It's quite a remarkable difference.

Dave

On 16 Sep, 2008, at 7:10 PM, Jason Coco wrote:

if you're creating lots of short-lived things in a loop or something, create your own autorelease pool:

while (loopConditionIsTrue) {
NSAutoreleasePool *myPool = [[NSAutoReleasePool alloc] init];
NSMutableString *str = [NSMutableString string];
/* do stuff */
[myPool drain]; // all your autorelease objects created within the loop will be freed here
}


/jason

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSMutableString question (From: John Zorko <email@hidden>)
 >Re: NSMutableString question (From: Dave DeLong <email@hidden>)
 >Re: NSMutableString question (From: Jason Coco <email@hidden>)

  • Prev by Date: Re: NSMutableString question
  • Next by Date: Re: NSMutableString question
  • Previous by thread: Re: NSMutableString question
  • Next by thread: Re: NSMutableString question
  • Index(es):
    • Date
    • Thread