Re: Purpose of [NSAutoreleasePool drain] ?
Re: Purpose of [NSAutoreleasePool drain] ?
- Subject: Re: Purpose of [NSAutoreleasePool drain] ?
- From: Nicko van Someren <email@hidden>
- Date: Thu, 16 Jun 2005 13:18:19 +0100
On 16 Jun 2005, at 12:53, Matt Gough wrote:
I notice that Tiger has [NSAutoreleasePool drain]
Why would I want to drain instead of release?
Less overhead. Whereas you might write:
for(i=0;i<100000;i++) {
NSAutoreleasePool *arp = [NSAutoreleasePool new];
// Do lots of object thrashing
[arp release];
}
You can instead write:
NSAutoreleasePool *arp = [NSAutoreleasePool new];
for(i=0;i<100000;i++) {
// Do lots of object thrashing
[arp drain];
}
[arp release];
Which has the same memory consumption characteristics but does 10,000
fewer object allocations and initialisations.
Generally, anywhere you might have released an NSAutoreleasePool and
then allocated a new one you can drain the existing one instead. As
far as I can tell 'drain' does NOT shrink the data structures used by
the pool. Since ARPs grow as you add more objects the I suspect that
there is a second efficiency saving because, in a loop like the one
above, after the first pass the pool will already be large enough to
cope with the expected number of autoreleases and there will be less
activity involved in growing each new pool each time you go around
the loop.
Nicko
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden