• 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: Purpose of [NSAutoreleasePool drain] ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Purpose of [NSAutoreleasePool drain] ?
      • From: Jim Correia <email@hidden>
References: 
 >Purpose of [NSAutoreleasePool drain] ? (From: Matt Gough <email@hidden>)

  • Prev by Date: Purpose of [NSAutoreleasePool drain] ?
  • Next by Date: Re: Purpose of [NSAutoreleasePool drain] ?
  • Previous by thread: Purpose of [NSAutoreleasePool drain] ?
  • Next by thread: Re: Purpose of [NSAutoreleasePool drain] ?
  • Index(es):
    • Date
    • Thread