// -valueForAttributeCopy:
// Returns an object typed id representing the value for a given attribute of the receiver's AXUIElement or nil if the attribute doesn't exist.
// The sender is responsible for releasing the object.
- (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;
}
(where _element is an instance variable with an AXUIElementRef, stored in my AXUIElement wrapper class object.)
In the calling method, I compare the returned object against the value I'm looking for and then release it by calling [value release].
Do you think it is bad practice to cast CFTypeRefs to type id and releasing them this way?
As I mentioned, ObjectAlloc tells me that my app doesn't accumulate memory allocations, while the other app does.
Or am I wrong in that my app is not able (and not allowed) to retain objects in another app's memory space?
Peter