Re: Question about UIElementRefs
Re: Question about UIElementRefs
- Subject: Re: Question about UIElementRefs
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 26 Nov 2003 12:15:33 -0500
on 2003-11-26 9:09 AM, Andrew Taylor at email@hidden wrote:
>
My program caches UIElementRefs for windows that it has notifiers
>
for. Upon occasion, the program will do a CFEqual to determine if two
>
UIElementRefs are equal, and it will crash inside CFEqual. I think
>
this typically occurs after a window has closed and my program does
>
not know it yet (once it does, cached values are zeroed). I know that
>
the UIElementRefs are NOT zero, the program checks the arguments for
>
nonzero before calling CFEqual.
I discussed this issue at length with the Apple engineers about a year ago.
The consensus was that the only safe way to handle this issue is to register
for the element-destroyed notification for every UIElementRef you create. I
do this in PreFab UI Browser, and it works like a charm.
The code isn't really too complex. Whenever I create a UIElementRef that I
intend to keep around, I also create an observer and register it for the
element-destroyed notification. I have a callback function that is dedicated
to handling the receipt of this notification and no other. This
special-purpose callback function simply sets a variable that is associated
with this UIElementRef to mark it as destroyed, and I always check the
variable before attempting to do anything with the UIElementRef.
UIElementRefs for destroyed elements (like closed windows) can contain
either garbage, or real UIElementRef data for SOME OTHER ELEMENT. So you
won't always crash if you don't take these precautions, but you will almost
certainly get bad data.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
accessibility-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/accessibility-dev
Do not post admin requests to the list. They will be ignored.