• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps


  • Subject: Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
  • From: Christiaan Hofman <email@hidden>
  • Date: Thu, 11 Nov 2010 14:42:13 +0100


On Nov 11, 2010, at 14:21, Bill Cheeseman wrote:


On Nov 11, 2010, at 7:04 AM, Peter Lübke wrote:

- (id)valueForAttributeCopy:(CFStringRef)attribute
{
id value = nil;
id axValue = nil;
NSArray *attrNames;

if (AXUIElementCopyAttributeNames((CFTypeRef)_element, (CFArrayRef *)&attrNames) == kAXErrorSuccess)
{
if ( [attrNames indexOfObject:(NSString *)attribute] != NSNotFound && AXUIElementCopyAttributeValue((CFTypeRef)_element, attribute, (CFTypeRef *)&axValue) == kAXErrorSuccess )
value = axValue;
}
[attrNames release];

return value;
}

I believe it's OK to cast a CFTypeRef to a toll-free-bridged NSObject and then 'release' or 'autorelease' it instead of 'CFReleas'ing it.

However, you have neglected to CFRelease (or release, or autorelease) the value stored in axValue by the AXUIElementCopyAttributeValue() function call in the body of your method The Cocoa convention is that a method like your -valueForAttributeCopy: always returns an object autoreleased. So, you might want to add '[axValue autorelease]' or '[value autorelease]' before the return, or change the last line to 'return [value autorelease]', and see what happens. (If the caller of your method does releases its return value when done with it, remove that release because it would be automatically released by the autorelease added in your method).

--

Bill Cheeseman - email@hidden

Actually, no. The docs (Memory Management Programming Guide) say that the returned value in this case should be retained:

"You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” "

Note the word "contains", which only applies to "copy".

(I personally think this rule is wrong, or at least formulated wrongly and inconsistently in the docs. For instance compare a method initWithObjects:copyItems: which clearly *contains* the word "copy" but whose return value isn't explicitly retained. But Apple does not agree with me, and they refuse to be unambiguous in the docs, even though it's pretty straightforward to be clear.)

Apart from this, I would advice to just avoid any confusion, and rename the method: either name it -valueForAttribute: and autorelease the value, or name it -copyValueForAttribute:.

Christiaan


 _______________________________________________
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

  • Follow-Ups:
    • Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
      • From: Bill Cheeseman <email@hidden>
References: 
 >Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps (From: Bill Cheeseman <email@hidden>)
 >Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps (From: Peter Lübke <email@hidden>)
 >Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
  • Next by Date: Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
  • Previous by thread: Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
  • Next by thread: Re: Performance slowdown when traversing UIElements under menu bar of Mail and some other apps
  • Index(es):
    • Date
    • Thread