首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >NSImage泄露?

NSImage泄露?
EN

Stack Overflow用户
提问于 2009-11-16 01:53:09
回答 1查看 604关注 0票数 3

因此,我正在尝试在我的应用程序中复制SourceView示例。我可以完美地生成源代码列表,很好。我还可以展开容器,一切都显示得很好。但是,当我在列表中选择一个项目时,应用程序崩溃并显示EXC_BAD_ACCESS。

回溯

代码语言:javascript
运行
复制
#0  0x7fff86532340 in objc_msgSend_vtable14
#1  0x7fff8508f622 in -[NSImage _deallocAuxiliaryStorage]
#2  0x7fff8508f5a1 in -[NSImage dealloc]
*#3 0x100002913 in -[SourceListCell setImage:] at SourceListCell.m:23
*#4 0x100001c31 in -[ProjectController outlineView:willDisplayCell:forTableColumn:item:] at ProjectController.m:166
#5  0x7fff85103085 in -[NSTableView preparedCellAtColumn:row:]
#6  0x7fff8511bc3f in -[NSTableView _drawContentsAtRow:column:withCellFrame:]
#7  0x7fff8511bbb5 in -[NSOutlineView _drawContentsAtRow:column:withCellFrame:]
#8  0x7fff8511acd8 in -[NSTableView drawRow:clipRect:]
#9  0x7fff8511a5cb in -[NSTableView drawRowIndexes:clipRect:]
#10 0x7fff8511a44c in -[NSOutlineView drawRowIndexes:clipRect:]

SourceListCell

代码语言:javascript
运行
复制
@interface SourceListCell : NSTextFieldCell {
    NSImage *image;
}

@property(nonatomic, retain) NSImage *image;

@end

- (id)init {
    self = [super init];

    [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];

    return self;
}

- (void)dealloc {
    [image release];
    image = nil;
    [super dealloc];
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
    if (image != nil) {
        [image setSize:NSMakeSize(kIconImageSize, kIconImageSize)];
        // the cell has an image: draw the normal item cell
        NSSize imageSize;
        NSRect imageFrame;

        imageSize = [image size];
        NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);

        imageFrame.origin.x += kImageOriginXOffset;
        imageFrame.origin.y -= kImageOriginYOffset;
        imageFrame.size = imageSize;

        if ([controlView isFlipped])
            imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
        else
            imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
        [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];

        NSRect newFrame = cellFrame;
        newFrame.origin.x += kTextOriginXOffset;
        newFrame.origin.y += kTextOriginYOffset;
        newFrame.size.height -= kTextHeightAdjust;
        [super drawWithFrame:newFrame inView:controlView];
    }
}

大纲视图委托

代码语言:javascript
运行
复制
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn*)tableColumn item:(id)item {
    if ([[tableColumn identifier] isEqualToString:COLUMNID_NAME]) {
            if ([cell isKindOfClass:[SourceListCell class]]) {
                //item = [item representedObject];
                NSImage *iconImage;
                iconImage = [[NSWorkspace sharedWorkspace] iconForFile:[item path]];
                [item setNodeIcon:iconImage];

                [(SourceListCell*)cell setImage:[item nodeIcon]];

            }
    }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-11-18 09:43:40

问题出在我的自定义NSTextFieldCell中:我需要实现copyWithZone。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1738255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档