【发布时间】:2014-01-27 22:09:33
【问题描述】:
我需要一些帮助来了解导致我的应用程序泄漏的原因。应用程序使用 ARC。我在一个窗口上有一个 NSView,用作文件的放置区。当您将文件拖到窗口上时,我会选择路径和文件名以在应用程序的其他方面使用。
当我通过 Instruments 运行应用程序时,一启动应用程序就会出现内存泄漏。下面是 Instruments 中返回的快照的链接:
http://f-video.s3.amazonaws.com/leak.jpg
下面是我的自定义类 (dropZone) 的拖放代码。
我需要这方面的教训。我不明白如何读取 Instruments 中返回的数据以进行更正。
感谢您的帮助。
@implementation dropZone
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
[self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
/*NSRect bounds = [self bounds];
[[NSColor grayColor] set];
[NSBezierPath fillRect:bounds];*/
}
- (NSDragOperation)draggingEntered:(id )sender {
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
if (sourceDragMask & NSDragOperationLink) {
return NSDragOperationLink;
} else if (sourceDragMask & NSDragOperationCopy) {
return NSDragOperationCopy;
}
}
return NSDragOperationNone;
}
- (BOOL)performDragOperation:(id )sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
// Perform operation using the list of files
NSLog(@"Dragged files");
int i;
for (i = 0; i < [files count]; i++) {
NSLog(@"%@",[files objectAtIndex:i]);
NSString * new = [files objectAtIndex:i];
[[NSApp delegate] updateText:new];
}
}
return YES;
}
@end
【问题讨论】:
标签: cocoa memory-leaks drag-and-drop nsview