The Leaks Instrument identifies a call to bookmarkDataWithContentsOfURL: as a leak. The code is next, although I don't think there's much to see:
The History pane of the Leaks instrument shows a single malloc() of type CFData, size 48, at the line marked LEAK above... Well, ok. By the naming of bookmarkDataWithContentsOfURL: I really really thought that it should be an autoreleased object returned...
But if I suppose for a moment that I'm wrong, or even that Apple might have made a silly mistake, I think to myself, "ok, so it's not autoreleased-- I'll add that line myself". If I do that, ( uncomment the line marked BURN ), then instead of the fixing the problem, the app bursts into flames in a short while. Profiling Zombies in that case, I get the following, quite different history for the returned object, ( I abbrev'ed autorelease for the sake of forum posting ) :
So, in short: if I don't add an autorelease, then I get a leak. If I do add an autorelease, then I get a zombie.
I find that just a wee bit aggravating. Am I missing something? What's going on here??
Code:
NSURL* applFromAlias( NSURL* aliasURL ) {
NSData* bookmark = [NSURL bookmarkDataWithContentsOfURL:aliasURL error:0]; // LEAK
if ( ! bookmark )
return 0;
NSError* error = 0;
NSURL* original = [NSURL
URLByResolvingBookmarkData:bookmark
options:NSURLBookmarkResolutionWithoutUI
relativeToURL:0
bookmarkDataIsStale:0
error:&error];
// [bookmark autorelease]; // BURN
if ( error )
return 0;
return original;
}
The History pane of the Leaks instrument shows a single malloc() of type CFData, size 48, at the line marked LEAK above... Well, ok. By the naming of bookmarkDataWithContentsOfURL: I really really thought that it should be an autoreleased object returned...
But if I suppose for a moment that I'm wrong, or even that Apple might have made a silly mistake, I think to myself, "ok, so it's not autoreleased-- I'll add that line myself". If I do that, ( uncomment the line marked BURN ), then instead of the fixing the problem, the app bursts into flames in a short while. Profiling Zombies in that case, I get the following, quite different history for the returned object, ( I abbrev'ed autorelease for the sake of forum posting ) :
Code:
0 0x1006f8fb0 CFData Malloc 1 00:37.454.427 512 DockMotor applFromAlias
1 0x1006f8fb0 CFData A'lease - 00:37.454.470 0 DockMotor applFromAlias
2 0x1006f8fb0 CFData CFRetain 2 00:37.454.531 0 DockMotor applFromAlias
3 0x1006f8fb0 CFData CFRelease 1 00:37.454.660 0 DockMotor applFromAlias
4 0x1006f8fb0 CFData A'lease - 00:37.454.662 0 DockMotor applFromAlias
5 0x1006f8fb0 CFData CFRelease 0 00:37.454.887 0 AppKit NSCoreDragTrackingProc
6 0x1006f8fb0 CFData Zombie -1 00:37.454.910 0 AppKit NSCoreDragTrackingProc
So, in short: if I don't add an autorelease, then I get a leak. If I do add an autorelease, then I get a zombie.
I find that just a wee bit aggravating. Am I missing something? What's going on here??