Re: Object Allocations
Re: Object Allocations
- Subject: Re: Object Allocations
- From: Rainer Brockerhoff <email@hidden>
- Date: Mon, 17 Sep 2001 15:51:11 -0300
>
Date: Mon, 17 Sep 2001 07:47:08 -0700
>
From: Rosyna <email@hidden>
>
>
-(void) awakeFromNib
>
{
>
// more
>
[NSThread detachNewThreadSelector:@selector(thread:) toTarget:self
>
withObject:nil];
>
// more
>
>
}
>
>
then
>
>
-(void) thread:(id)anObject
>
{
>
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>
// much more
>
[pool release];
>
}
I've been having similar - though intermittent - problems. My own code follows the pattern:
// subclassed NSDocument, when opening a document:
// shouldThread is a BOOL instance variable set from preferences.
if (shouldThread) {
[NSApplication detachDrawingThread:@selector(startPlugin:)
toTarget:self withObject:plugin];
} else {
[self startPlugin:plugin];
}
- (void)startPlugin:(id)plugin {
NSAutoreleasePool* pool = nil;
if (shouldThread) {
pool = [[NSAutoreleasePool alloc] init];
}
[plugin doStuff];
[pool release];
}
As I said, it's intermittent. This may not be pertinent to the problem, but the error message (NSAutoReleaseNoPool IIRC) always refers to a NSCFString and an NSCalibratedRGBColor, it happens only for the first opened document, and most - perhaps all - instances I remember seeing happened when the document was opened from within a drag&drop receiver.
The shouldThread variable is set very early when the document is created and never changes afterwards. Even if some evil influence changed it between detachDrawingThread and the test before the NSAutoreleasePool, _all_ temporary objects created by doStuff would be pool-less, not just the two which appear in the messages.
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://www.brockerhoff.net/ (updated July 2000)