AXObserverCreate and Garbage Collection
AXObserverCreate and Garbage Collection
- Subject: AXObserverCreate and Garbage Collection
- From: Brian Krisler <email@hidden>
- Date: Thu, 9 Oct 2008 21:19:42 -0400
Hi,
I have an application that sets up a few listeners to active
applications
using AXObserverCreate. Since my recent replacement of an old PPC
laptop to a brand new MacBook Pro, my application crashes upon the
first attempted callback from an AXObserverAddNotification.
I think this issue is related to GC in that the AXObserverRef is getting
getting garbage collected, however I can not prove this. What is the
proper way to prevent the garbage collector from claiming my observer
objects?
Here is my current code:
- (BOOL)watchApplication:(NSString*)application withDictionary:
(NSMutableDictionary *)applicationDictionary
{
AXError err = kAXErrorSuccess;
AXObserverRef observer;
pid_t applicationPID = [[applicationDictionary
valueForKey:@"NSApplicationProcessIdentifier"] intValue];
err = AXObserverCreate(applicationPID, notificationCallback,
&observer);
if(err == kAXErrorSuccess) {
CFRunLoopAddSource(CFRunLoopGetCurrent(),
AXObserverGetRunLoopSource(observer), kCFRunLoopDefaultMode);
AXUIElementRef element = AXUIElementCreateApplication(applicationPID);
[applicationDictionary setObject: (id)element forKey: @"app_element"];
[applicationDictionary setObject: (id)observer forKey:
@"app_observer"];
[knownObservers setObject:(id)observer forKey:application];
[knownElements setObject:(id)element forKey:application];
err = AXObserverAddNotification(observer, element,
kAXMenuItemSelectedNotification, applicationDictionary);
}
return (err == kAXErrorSuccess) ? YES : NO;
}
Thanks for any help.
Brian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden