Search code examples
objective-ccocoanstableviewappkit

EXC_BAD_ACCESS [NSTableView _dataSourceValueForColumn:row:] in Mavericks only


I've been reported more and more often about crashes due to a EXC_BAD_ACCESS exception in my app, by users on Mavericks. However, I can't figure out why, and I can't reproduce it.

Any idea what I what insights I could get from the log below? Is something wrong with the datasource of the table?

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000024048904

VM Regions Near 0x24048904: 
MALLOC_LARGE 000000001a362000-000000001aa92000 [ 7360K] 
rw-/rwx SM=PRV 
--> 
__TEXT 0000000050000000-00000000502c5000 [ 2836K] 
r-x/rwx SM=COW 
/System/Library/Extensions/AMDRadeonX3000GLDriver.bundle/Contents/MacOS/AMDRadeonX3000GLDriver

Application Specific Information: 
objc_msgSend() selector name: count

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 
0 libobjc.A.dylib 0x93b930ab objc_msgSend + 27 
1 com.apple.AppKit 0x970b6305 -[NSTableView 
_dataSourceValueForColumn:row:] + 69 
2 com.apple.AppKit 0x971ba127 -[NSTableView 
preparedCellAtColumn:row:] + 385 
3 com.apple.AppKit 0x971b9e25 -[NSTableView 
_drawContentsAtRow:column:withCellFrame:] + 50 
4 com.apple.AppKit 0x971b9bf2 -[NSTableView 
drawRow:clipRect:] + 1502 
5 com.apple.AppKit 0x971b94bf -[NSTableView 
drawRowIndexes:clipRect:] + 801 
6 com.apple.AppKit 0x9708cc94 -[NSTableView drawRect:] 
+ 1254 
7 com.apple.AppKit 0x97072194 -[NSView(NSInternal) 
_recursive:displayRectIgnoringOpacity:inGraphicsContext:CGContext:topView:shouldChangeFontReferenceColor:] 
+ 1174 
8 com.apple.AppKit 0x97071bec 
__46-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke + 220 
9 com.apple.AppKit 0x97071971 -[NSView(NSLayerKitGlue) 
_drawViewBackingLayer:inContext:drawingHandler:] + 2237 
10 com.apple.AppKit 0x970710a8 -[NSView(NSLayerKitGlue) 
drawLayer:inContext:] + 116 
11 com.apple.AppKit 0x97071029 -[_NSViewBackingLayer 
drawInContext:] + 65 

Solution

  • The cause may be you still storing NSTableView dataSource or delegate reference as it is said above the properties setter and getter methods in NSTableView.h

    The dataSource is a weak reference (non retained) in non garbage collected applications. Under garbage collected apps, it is a strong reference.

    Try to call some special method when you are about to destruct your view with all the children including table view.

    - (void)shutdown
    {
      self.tableView.dataSource = nil;
      self.tableView.delegate = nil;
    }