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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to