Re: Programatically detect if any autorelease pool exists?
Re: Programatically detect if any autorelease pool exists?
- Subject: Re: Programatically detect if any autorelease pool exists?
- From: Jim Correia <email@hidden>
- Date: Wed, 6 Sep 2006 11:43:47 -0400
On Sep 6, 2006, at 11:35 AM, Sean McBride wrote:
Even if it did, who would be responsible for releasing and replacing
the pool? Without someone periodically "draining" the autorelease
pool, your heap would grow unbounded.
True. But at least a 'pool of last resort' (created very early) would
stop the errors about having 'no pool in place' and stop the freaky
crashes due to pools coming and going when they shouldn't. Alas,
since
this is a library, I don't have access to main(), and unfortunately
there is no vtkinit() to do any setup in.
How about if I create a simple C++ class who's ctor checks if there
is a
pool (via +autoreleasePoolExists-- thanks Jonathon!) and creates
one if
there isn't one. Then I allocate a global/static instance of that
object. Then any app that links to the vtk library will have a
'pool of
last resort', created even before main(), right? Does that seem
reasonable?
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. 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.)
If your framework is going to be autoreleasing objects, as
distasteful as it is, you are going to have to
- manage the autorelease pools at all the "top-level" entry points [1]
- required Mac OS X users of this library to manage the autorelease
pool in their main event loop (possibly providing a template and or
callbacks to help)
[1] As John Stiles hinted at, you can make this easier by just using
a stack-based object at the top of your methods.
VTKObject::someMethod()
{
VTKAutoreleasePool pool;
doWork();
}
VTKAutoreleasePool::VTKAutoreleasePool()
{
mPool = [[NSAutoreleasePool alloc] init];
}
VTKAutoreleasePool::!VTKAutoreleasePool()
{
[mPool release];
}
Jim
_______________________________________________
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