initWithContentsOfFile Leak
initWithContentsOfFile Leak
- Subject: initWithContentsOfFile Leak
- From: Chris Outwin <email@hidden>
- Date: Tue, 14 Mar 2006 16:05:29 -0600
I have worked for a day trying to find an initWithContentsOfFile
leak. The mail list and Google haven't helped.
My Xcode 2.2, OS X 10.4.5, Cocoa app has a NSImageView subclass which
implements:
- (UInt32)performDragOperation:(id <NSDraggingInfo>)sender
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
- (UInt32)prepareForDragOperation:(id <NSDraggingInfo>)sender
- (UInt32)performDragOperation:(id <NSDraggingInfo>)sender
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
MallocDebug indicates the leak occurs in initWithContentsOfFile after
the user drags an image file name from the Finder to the sub-classed
NSImageView. Here's the code:
- (UInt32)performDragOperation:(id <NSDraggingInfo>)sender {
NSPasteboard* pb = [sender draggingPasteboard];
NSString* desiredType = [pb availableTypeFromArray:[NSArray
arrayWithObject:NSFilenamesPboardType]];
NSData* carriedData = [pb dataForType:desiredType];
if (carriedData == nil) {
NSRunAlertPanel(@"Drag Operation Error in BFOSDragDropImage",
@"Data for type could not be obtained.", nil, nil, nil);
return NO;
}
else {
if ([desiredType isEqualToString:NSFilenamesPboardType]) {
NSArray* fileArray = [pb
propertyListForType:@"NSFilenamesPboardType"];
[self setPath:(NSString *)[fileArray objectAtIndex:0]];
[self setBfosImage:[[[NSImage alloc] initWithContentsOfFile:[self
path]] autorelease]];
// more code
The path and image accessor method have similar syntax such as:
- (NSString *)path {
return [[_path retain] autorelease];
}
- (void)setPath:(NSString *)newPath {
if (_path != newPath) {
[_path release];
_path = [newPath retain];
}
}
Both path and image objects are released in -(void)dealloc. What am
I missing? Thank you.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden