Re: Impossible leak warning in OS X init method
Re: Impossible leak warning in OS X init method
- Subject: Re: Impossible leak warning in OS X init method
- From: Bill Cheeseman <email@hidden>
- Date: Sat, 29 Aug 2015 15:42:31 -0400
On Aug 29, 2015, at 2:54 PM, Jens Alfke <email@hidden> wrote:
Is it possible that, in removing details from your code, you left out some detail that’s what’s causing the warning? Do you mind posting the actual method, copied/pasted verbatim from Xcode?
You asked for it! -- sorry about the formatting.
- (id)initWithElementRef:(AXUIElementRef)uiElementRef delegate:(id)aDelegate {
if ((self = [super init])) {
if (uiElementRef != NULL) {
CFTypeRef role = NULL;
AXError err = AXUIElementCopyAttributeValue(uiElementRef, kAXRoleAttribute, &role);
if (err == kAXErrorSuccess) { // AXRole attribute of uiElementRef was successfully copied
if (CFEqual(role, kAXApplicationRole)) {
pid_t pid = 0;
AXUIElementGetPid(uiElementRef, &pid);
id newSelf = [[[PFApplicationUIElement applicationUIElementClass] alloc] initWithPid:pid delegate:aDelegate];
[self release];
self = newSelf;
} else {
elementRef = (AXUIElementRef)CFRetain(uiElementRef); // Save uiElementRef in this element's elementRef instance variable; it is CFReleased in -invalidate or -dealloc.
[self setDelegate:aDelegate];
[self setElementInfo:[self cacheElementInfo]];
[self registerDestructionObserver];
isValid = YES;
}
/*if (role) */CFRelease(role);
} else { // could not copy AXRole attribute of uiElementRef
if (err == kAXErrorInvalidUIElement) { // uiElementRef is destroyed
// Return a PFUIElement object without an elementInfo cache.
elementRef = (AXUIElementRef)CFRetain(uiElementRef); // Save uiElementRef in this element's elementRef instance variable; it is CFReleased in -invalidate or -dealloc.
isValid = YES;
} else {
[self release];
self = nil;
#ifdef PFA_DEBUG
NSLog(@"PFUIElement -initWithElementRef:delegate: method, error %@ while getting the AXRole attribute of a newly-created UI element.", [PFUIElement descriptionForError:err]);
#endif
}
}
} else {
[self release];
self = nil;
}
}
return self;
}
- (PFUIElement *)elementAtPoint:(NSPoint)point {
AXUIElementRef ref = NULL;
AXError err = AXUIElementCopyElementAtPosition([self elementRef], point.x, point.y, &ref);
if (err == kAXErrorSuccess) {
PFUIElement *element = [[PFUIElement alloc] initWithElementRef:ref delegate:[self delegate]];
if (ref) CFRelease(ref);
return [element autorelease];
}
// Log errors.
#ifdef PFA_DEBUG
NSLog(@"PFUIElement -elementAtPoint: instance method, error %@ for point %@.", [PFUIElement descriptionForError:err], NSStringFromPoint(point));
#endif
if ([[self delegate] respondsToSelector:@selector(PFUIElementReportError:)]) {
NSString *descriptionPrefix = NSLocalizedStringFromTableInBundle(@"Could not read the screen", @"PFAssistiveErrors", [NSBundle bundleForClass:[PFUIElement class]], @"Description prefix for -[PFUIElement elementAtPoint:]");
NSString *failureReasonSuffix = [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"while reading the screen at %@", @"PFAssistiveErrors", [NSBundle bundleForClass:[PFUIElement class]], @"Failure reason suffix for -[PFUIElement elementAtPoint:]"), NSStringFromPoint(point)];
NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:descriptionPrefix, PFAssistiveDescriptionPrefixErrorKey, failureReasonSuffix, PFAssistiveFailureReasonSuffixErrorKey, self, PFAssistiveElementErrorKey, [NSNumber numberWithBool:NO], PFAssistiveIsExpectedErrorKey, NULL];
[[self delegate] PFUIElementReportError:[PFAssistiveError errorWithDomain:PFAssistiveErrorDomain code:err userInfo:userInfo]];
}
return nil;
}
--
Bill Cheeseman - email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden