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: Memo Akten <email@hidden>
- Date: Wed, 25 Feb 2009 17:55:58 +0000
Ah ok, thats what I wasn't sure about, whether or not the pool would
be released after every timer update. So if no events come in for a
few seconds, I"ll have my runloops autorelease pool swelling up -
which is not desired. My solution of creating my own autorelease pool
before all app update+draw works, but is there a convention for the
handling of this situation? Create my own autorelease pool vs. posting
a fake event? For readability sake I guess creating a second pool
makes more sense?
On 25 Feb 2009, at 16:44, Michael Ash wrote:
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
_______________________________________________
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