Re: do i need to create autorelease pool?
Re: do i need to create autorelease pool?
- Subject: Re: do i need to create autorelease pool?
- From: Michael Ash <email@hidden>
- Date: Wed, 25 Feb 2009 11:44:30 -0500
On Wed, Feb 25, 2009 at 12:00 AM, Peter N Lewis <email@hidden> wrote:
>> The Application Kit creates an autorelease pool on the main thread at the
>> beginning of every cycle of the event loop, and drains it at the end,
>> thereby releasing any autoreleased objects generated while processing an
>> event.
>
> This is assuming iPhone or Leopard, I believe the NSAutoreleasePool creation
> was required for older versions of Mac OS X.
The semantics haven't changed on Leopard as far as I know. The above
has been the case forever: pools are created and destroyed on
*events*, but not timers. If you simply run a timer forever and never
process events, your memory usage will grow without limit. A pool
exists, so you don't explicitly leak, but the pool is only drained
when an event arrives. If you're going to be running something in
timers or other non-event sources, you'll want to post a fake event to
the main event loop from time to time (or just after every action you
take) to force the pool to drain.
I have *no* idea how much of that, if any, applies to the iPhone. In
any case if you're processing events on a regular basis as well then
you don't have to worry about anything.
Mike
_______________________________________________
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