Objective C: Why is this code leaking?
- by Johnny Grass
I'm trying to implement a method similar to what mytunescontroller uses to check if it has been added to the app's login items. This code compiles without warnings but if I run the leaks performance tool I get the following leaks:
Leaked Object # Address Size Responsible Library Responsible Frame
NSURL 7 < multiple > 448 LaunchServices LSSharedFileListItemGetFSRef
NSCFString 6 < multiple > 432 LaunchServices LSSharedFileListItemGetFSRef
Here is the responsible culprit:
- (BOOL)isAppStartingOnLogin
{
LSSharedFileListRef loginListRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
if (loginListRef) {
NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginListRef, NULL);
NSURL *itemURL;
for (id itemRef in loginItemsArray) {
if (LSSharedFileListItemResolve((LSSharedFileListItemRef)itemRef, 0, (CFURLRef *) &itemURL, NULL) == noErr) {
if ([[itemURL path] hasPrefix:[[NSBundle mainBundle] bundlePath]]) {
[loginItemsArray release];
CFRelease(loginListRef);
return YES;
}
}
}
[loginItemsArray release];
CFRelease(loginListRef);
}
return NO;
}