• 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: Impossible leak warning in OS X init method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Leakage from UILabel?
  • Next by Date: How to intercept the space key in an NSTextField
  • Previous by thread: Leakage from UILabel?
  • Next by thread: How to intercept the space key in an NSTextField
  • Index(es):
    • Date
    • Thread