Re: Update Cocoa object from callback
Re: Update Cocoa object from callback
- Subject: Re: Update Cocoa object from callback
- From: Luke Bellandi <email@hidden>
- Date: Tue, 20 May 2003 14:37:27 -0700
You've got a couple things going on here. If you're doing anything
with AppKit in your callback (like updating a view or other UI widget),
you want to make sure to do it on the main thread. This can be
accomplished by using NSObject's 'performSelectorOnMainThread' call.
Doing things in AppKit in threads other than your app's main thread is
ill-advised.
So a call that looked like "[self updateMyView:data];" would translate
into "[self performSelectorOnMainThread:@selector(updateMyView:)
withObject:data waitUntilDone:NO];"
The message "_NSAutoreleaseNoPool(): Object 0x17f7ab0 of class
NSCFNumber autoreleased with no pool in place - just leaking" is
appearing because Cocoa's convenience constructors autorelease the
objects they return, so:
[NSNumber numberWithUnsignedInt:myValue] is exactly the same as
[[[NSNumber alloc] initWithUnsignedInt:myValue] autorelease];
Now, functions executing on your application's main run loop have
autorelease pools created for them by the application. Since CoreAudio
callbacks often are not called on the main thread (exception: see the
CoreAudio.framework property 'kAudioHardwarePropertyRunLoop'), you
don't have an autoreleasePool to manage those objects. Try the
following code in your listener:
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(updateMyView:)
withObject:[NSNumber numberWithUnsignedInt:myValue] waitUntilDone:NO];
[pool release];
}
Luke.
On Tuesday, May 20, 2003, at 02:15 PM, Mark's Studio wrote:
How do i notify my Cocoa object with a value from within the callback?
i tried with NSNotification
[[NSNotificationCenter defaultCenter] postNotificationName:@"Update"
object:[NSNumber numberWithUnsignedInt:myValue]]
but i get this in the console
_NSAutoreleaseNoPool(): Object 0x17f7ab0 of class NSCFNumber
autoreleased with no pool in place - just leaking
should i post notification with object:nil and then [myCocoaObject
setValue: myValue];
or what is the proper way to do this?
is AUListenerCreate something that can be used with Cocoa?
I looked at all the fine examples, but C++ is not my friend, so i did
not learn much from them.
Peter Mark
Mark's Recording Studio A/S
Lundeskovsvej 3 2900 Hellerup
Denmark
Tel: +45 35366078 Fax: +45 35366038
www.marks-studio.dk
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.
_______________________________________________
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.