Re: Re: Programatically detect if any autorelease pool exists?
Re: Re: Programatically detect if any autorelease pool exists?
- Subject: Re: Re: Programatically detect if any autorelease pool exists?
- From: "Clark Cox" <email@hidden>
- Date: Wed, 6 Sep 2006 14:25:48 -0400
On 9/6/06, Sean McBride <email@hidden> wrote:
On 2006-09-06 11:43, Jim Correia said:
>The only thing creating a "pool of last resort" solves is the
>messages logged to the console about there being no autorelease pool
>in place.
Well, that, and it lets me get rid of the pool creation in that other
object's ctor, which leads to crashes when pools appear and disappear at
the wrong times.
>Since the pool will never be drained, your heap will
>continue to grow unbounded (until you are swapping like crazy, or run
>out of address space.)
Yes, there will be leaks, but that's better than crashes. :)
I've tried to avoid discussing vtk too much, since it's big and
complicated, and somewhat tangential to my original question
(programatically detecting if any autorelease pool exists). But if you
look at this sample real fast:
<http://public.kitware.com/VTK/example-code.php>
you'll see in main() that there are a bunch of objects created, then the
Start() method is called to start the event loop. All the objects
created before Start() are possibly implemented using Cocoa, or call
other Cocoa code, and thus may autorelease objects. The Start() method
calls [NSApp run] which will create and destroy pools for every event,
if I understand correctly. So a pool needs to exist pretty much by the
beginning of main(), since any vtk object created may potentially
autorelease an object. Once Start() is called, the regular Cocoa pool
system starts. So I think in reality there will be few leaks: only
objects autoreleased before Start() is invoked. Hmmmm, I wonder if I
could -release my 'pool of last resort' just before calling [NSApp run]
in Start()?
OK, in this case, if [NSApp run] is eventually called, then I see no
real problem with creating a global "pool of last resort" as you call
it. Of course, any objects in that pool will be leaked, but it seems
that these objects are only the ones created in things called by main
before Start() is called. I would imagine that this is a pretty small
and relatively fixed sized group of objects. Any objects autoreleased
after event processing starts will be handled by the event loop's
pool.
--
Clark S. Cox III
email@hidden
My CV/Resume:
http://homepage.mac.com/clarkcox3/files/Resume.pdf
http://homepage.mac.com/clarkcox3/files/Resume.html
_______________________________________________
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