Re: Leak while in Midi thread
Re: Leak while in Midi thread
- Subject: Re: Leak while in Midi thread
- From: Chris Reed <email@hidden>
- Date: Fri, 10 Jan 2003 10:48:28 -0600
On Friday, Jan 10, 2003, at 02:58 US/Central, Steve wrote:
Hi,
I have a method to display incoming notes on a Keyboard graphic which
includes:
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?).
Yes, the main app thread creates and releases an autorelease pool each
time throught the runloop.
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
I'm guessing that it's caused by the new Midi thread, and confusion
over which thread should release it?
Does anyone know either how to fix this, or at least have some clues
on how to track the problem down further?
Since the Midi read thread is created by CoreMIDI, it does not have an
autorelease pool associated with it. Just like any thread you create
with [NSThread detachNewThreadSelector:..] you have to create your own
autorelease pool and release it before you leave your read proc.
But... you really think hard about allocating or releasing anything in
a Midi read proc! That's a realtime (not as hard as audio, but still
realtime) thread that you really don't want to block on memory
allocation if at all possible. In your case, updating a graphic display
of incoming notes, it's not so big a problem--I do exactly the same
thing in MidiKeys. Not threads inside CoreMIDI process will themselves
be blocked by your read proc being really slow.
Audio callbacks are different. You absolutely do not want to create an
autorelease pool or do any allocation or deallocation! The only time I
create an autorelease pool in an audio callback is so I can use NSLog
while testing and debugging.
Here's what my Midi read method looks like:
- (void)receiveMidiPacketList:(const MIDIPacketList *)packetList
{
NSAutoreleasePool *pool = nil;
NS_DURING
pool = [[NSAutoreleasePool alloc] init];
...
[pool release];
NS_HANDLER
NSLog(@"exception occurred in receiveMidiPacketList: %@",
localException);
[pool release];
NS_ENDHANDLER
}
Notice that you also want to wrap the whole thing in an exception
handler to catch any Cocoa exceptions that might be raised.
Cheers
-chris
_______________________________________________
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.