Re: Leak while in Midi thread
Re: Leak while in Midi thread
- Subject: Re: Leak while in Midi thread
- From: Kurt Revis <email@hidden>
- Date: Fri, 10 Jan 2003 09:41:03 -0800
On Friday, January 10, 2003, at 12:58 AM, Steve wrote:
NSColor *myColor;
myColor = [NSColor colorWithCalibratedRed:0.25 green:0.95 blue:0.25
alpha:1.0];
When this is called programmatically, there is no problem, and the
NSColor is (I guess) being correctly auotreleased at some point.
(...next time round the event loop?).
Just to clear up your terminology: You mean "when this is called from
my main thread", and "correctly deallocated". The NSColor is
autoreleased right away, before
-colorWithCalibratedRed:green:blue:alpha: returns. When the autorelease
pool is deallocated (at the end of the event loop), the NSColor is
released for real. If its retain count is then 0 (as it should be) it
will be deallocated.
However the same method can also be called from my Midi readProc.
When this happens, I get the following error log:
>2003-01-10 08:32:20.442 ChordCompleteDebug[788] ***
_NSAutoreleaseNoPool(): Object 0x19c52d0 of class
>NSCalibratedRGBColor autoreleased with no pool in place - just > leaking
Make your read proc look like this:
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// your code here
[pool release];
}
Your read proc is being called in a separate thread which CoreMIDI
created. CoreMIDI doesn't set up an autorelease pool in this thread
(since it doesn't use Cocoa internally) so you have to do it yourself.
You can probably search the archives of the Cocoa-Dev list for
"NSAutoreleaseNoPool" for more details. This question comes up a lot.
--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.