title: When TableView's DataSource Array Changes, App Crashes
body: <p>I have an array of 5 items that is also used as the content for a tableview.  In the nib is a button that changes the content of the array to 5 different items.  When I click that button, however, the app crashes with an EXC_BAD_ACCESS.  I set a breakpoint on objc_exception _throw and had my suspicions confirmed.  The bad method is</p>
  
  <pre><code>- (id)tableView:(NSTableView *)wordsTableView
  objectValueForTableColumn:(NSTableColumn *)column
              row:(int)rowIndex
  {
      return [[currentCard words] objectAtIndex:rowIndex];
  }
  </code></pre>
  
  <p>currentCard is an instance of the GameCard class, and its array, words, is the array in question.  On first launch, it works fine, but if I try to change it, crash.</p>
  
  <p>----------EDIT----------</p>
  
  <p>In AppController's awakeFromNib: I have this</p>
  
  <pre><code>currentCard = [[GameCard alloc] init];
  </code></pre>
  
  <p>And in the button's IBAction, I have this:</p>
  
  <pre><code>[currentCard release];
  currentCard = [[GameCard alloc] init];
  </code></pre>
  
  <p>With zombies enabled, when I click the button, I get this from GDB:</p>
  
  <p>2009-06-22 18:55:03.368 25WordsMax[19761:813] *** -[CFArray objectAtIndex:]: message sent to deallocated instance 0x14ba00</p>
  
  <p>referring to the data source method.  I've been trying to track down the memory bug for hours, but am missing it.</p>
  
  <p>I got so frustrated I commented out every retain &amp; release (no autoreleases) in the code and still get 2009-06-22 19:41:58.564 25WordsMax[21765:813] *** -[CFArray objectAtIndex:]: message sent to deallocated instance 0x14c330 when I hit the button.</p>
  
  <p>And what is calling the datasource method? I'm not calling reloadData. If in my datasource method, I return @"A Word" for each row, everything runs fine. In GDB, I can even see my NSLogs printing the contents of the new array, all without a hitch. It's only when the datasource method as seen in the question gets called that any problems happen.</p>