Re: AXObserverCreate and Garbage Collection
Re: AXObserverCreate and Garbage Collection
- Subject: Re: AXObserverCreate and Garbage Collection
- From: Brian Krisler <email@hidden>
- Date: Mon, 13 Oct 2008 21:42:10 -0400
The problem ended up being a compiler setting however I have no
idea why it had any effect on the execution of my software.
After I selected the 'Build Active Architectures Only' switch,
everything worked.
Brian
On Oct 13, 2008, at 7:19 PM, James Dempsey wrote:
You might want to take a look at:
http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html
It talks about using GC with CoreFoundation, but the same general
principles apply for any CF-like API on Mac OS X, including the AX
APIs.
Looking at the code you provided, it looks like the AXObserver would
never be collected by CG, it is never made collectable (see the docs).
What does your crash log look like?
-James
On Oct 9, 2008, at 6:19 PM, Brian Krisler wrote:
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
--------------------------------------------------
James Dempsey
AppKit Engineering
Apple
email@hidden
_______________________________________________
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