I have a table view which uses an array controller for the contents, and as a 
data source and delegate so I can do drag and drop etc. It displays my data 
(Colors) just fine, but in one particular scenario something somewhere is 
over-releasing an NSIndexSet. I have stripped it right back to the following:

NSString *MovedColorRowIndicesType = @"MOVED_COLOR_ROW_INDICES_TYPE";
NSString *CopiedColorRowsType = @"COPIED_COLOR_ROWS_TYPE";

@implementation NMColorSetArrayController

- (void)awakeFromNib {    
        [colorSetTableView setDraggingSourceOperationMask:NSDragOperationLink 
forLocal:NO];
        [colorSetTableView setDraggingSourceOperationMask:(NSDragOperationCopy 
| NSDragOperationMove) forLocal:YES];
        [colorSetTableView registerForDraggedTypes:[NSArray 
arrayWithObjects:CopiedColorRowsType, MovedColorRowIndicesType, 
NSColorPboardType, @"NMThemedColor", nil]];
        [colorSetTableView setAllowsMultipleSelection:YES];
        [[colorSetTableView tableColumnWithIdentifier:@"Topic Colors"] 
setDataCell:[[[NMColorCell alloc] initImageCell:nil] autorelease]];
}

- (Class)objectClass {
        return [NSColor class];
}

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet 
*)rowIndices toPasteboard:(NSPasteboard *)pboard {
        return YES;
}

- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id 
<NSDraggingInfo>)info proposedRow:(int)row 
proposedDropOperation:(NSTableViewDropOperation)op {
    [tv setDropRow:row dropOperation:NSTableViewDropAbove];
   return NSDragOperationCopy;
}

- (BOOL)tableView:(NSTableView*)tv acceptDrop:(id <NSDraggingInfo>)info 
row:(int)row dropOperation:(NSTableViewDropOperation)op {
        [[info draggingPasteboard] clearContents];
        return NO;
}


Now what happens is that when I drag and drop within the table itself, all is 
fine, and when I drag a new color on from the color panel, it's fine. But if I 
drag to reorder the rows, and the drag a new color on, then it gives me an 
exception. If I turn zombies on, it tells me it's the same NSIndexSet that was 
passed in to the writeRowsWithIndexes... method earlier.

malloc_history shows that memory always having matching allocations and frees, 
until the last one, which is 
ALLOC 0x11e3b6270-0x11e3b628f [size=32]: thread_7fff7049dca0 |start | main | 
NSApplicationMain | -[OAApplication run] | -[NSApplication run] | 
-[OAApplication sendEvent:] | -[NSApplication sendEvent:] | -[NSWindow 
sendEvent:] | -[NSTableView mouseDown:] | -[NSTableView 
_performDragFromMouseDown:] | +[NSObject(NSObject) allocWithZone:] | 
_internal_class_createInstanceFromZone | calloc | malloc_zone_calloc 

So it was allocated when the previous operation (dragging to move the table 
rows) was performed, and according to malloc_history, it has never been freed.

If I put an extra retain on the the rowIndices in writeRowWithIndexes..., then 
I can drag on two colors before it crashes.

Given the fact that malloc_history doesn't show any release for the index set, 
I'm guessing that something is going wrong somewhere else and making a mess of 
my memory, but can't think of what could possibly do something like this.

The static analyser doesn't turn up anything relevant.

Any ideas where to look for the cause of this issue? I'm stumped.



Thanks

Gideon







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to