Re: Leak while in Midi thread
Re: Leak while in Midi thread
- Subject: Re: Leak while in Midi thread
- From: Jeff Moore <email@hidden>
- Date: Fri, 10 Jan 2003 10:56:46 -0800
This discussion seems like as good a time as any to remind people that
allocating and deallocating memory inside a time constraint thread such
as this MIDI thread or the HAL's IO thead is flat out bad programming.
The reason why is that the memory calls _will_ block (usually precisely
when you don't want them to) and cause you timing problems that are
very hard to diagnose. This is among the reasons why there are no
autorelease pools in these threads.
To reiterate: don't allocate or deallocate memory in a time constraint
thread owned by the audio or MIDI systems. You will get hurt by doing
so.
On Friday, January 10, 2003, at 08:05 AM, Philippe Wicker wrote:
On Friday, January 10, 2003, at 09:58 AM, 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?).
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?
Thanks
Steve
Hello Steve,
When you are calling Cocoa code from the MIDIReadProc, then you are at
some point in a C runtime environment, and you should wrap any call to
Cocoa method in so called C-Callable wrapper functions (have a look to
"Inside Mac OS X: Integrating Carbon and Cocoa in Your Application",
page 13).
OSStatus YourWrapper ( your C parameters )
{
NSAutoreleasePool *localPool;
localPool = [[NSAutoreleasePool alloc] init];
-> your message to the Cocoa object
[localPool release];
return noErr;
}
When doing this, you should be aware that the MIDI thread may be
blocked for an undefined amount of time if the calls to
[NSAutoreleasePool alloc] and [localPool release] actually falls into
low level memory allocation routines (like C malloc and free) which
are potentially blocking calls.
Regards.
Philippe Wicker
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.
--
Jeff Moore
Core Audio
Apple
_______________________________________________
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.