title: Why is the UICollectionViewDataSource deallocated when I try to call a method on it?
body: <p>Although I seem to be able to set up a <code>dataSource</code> onto a <code>UICollectionView</code> just fine in my view controller: </p>
  
  <pre><code>- (void)setupCollectionView:(UICollectionView*)collectionView {
      CustomCollectionViewDataSource *dataSource = [[CustomCollectionViewDataSource alloc] initWithCollectionView: collectionView];
      [collectionView setDataSource: dataSource];
      [collectionView setDelegate: self];
      [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kNNReuseIdentifier];
  }
  </code></pre>
  
  <p>When I log <code>collectionView</code>, <code>dataSource</code>, and <code>collectionView.dataSource</code>, they all look exactly like they are supposed to. I only have one section in my collection view, so I don't implement <code>numberOfSectionsInCollectionView</code> in my data source.</p>
  
  <p>Once my collection view loads, I get the app crashes. There is no related log for the crash with or without breakpoint exceptions on. When exception breakpoints are on, it doesn't point me to where my code is causing the problem. Upon crash, my stack looks like this: </p>
  
  <pre><code>* thread #1: tid = 0x22cc82, 0x01611411 CoreFoundation`___forwarding___ + 769, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
    * frame #0: 0x01611411 CoreFoundation`___forwarding___ + 769
      frame #1: 0x016110ee CoreFoundation`__forwarding_prep_0___ + 14
      frame #2: 0x00b0bc34 UIKit`-[UICollectionViewData _updateItemCounts] + 331
      frame #3: 0x00b0bce1 UIKit`-[UICollectionViewData _validateItemCounts] + 45
      frame #4: 0x00b0dc64 UIKit`-[UICollectionViewData numberOfSections] + 35
      frame #5: 0x00ad86ed UIKit`-[UICollectionView numberOfSections] + 62
      frame #6: 0x00af8614 UIKit`-[UICollectionViewFlowLayout(Internal) _getSizingInfos] + 205
      frame #7: 0x00af948f UIKit`-[UICollectionViewFlowLayout(Internal) _fetchItemsInfo] + 521
      frame #8: 0x00af4fe2 UIKit`-[UICollectionViewFlowLayout prepareLayout] + 157
      frame #9: 0x00b0bd9d UIKit`-[UICollectionViewData _prepareToLoadData] + 76
      frame #10: 0x00b0c5c5 UIKit`-[UICollectionViewData validateLayoutInRect:] + 56
      frame #11: 0x00ad2603 UIKit`-[UICollectionView layoutSubviews] + 173
      frame #12: 0x004f5964 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
      frame #13: 0x013b282b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
      frame #14: 0x0438145a QuartzCore`-[CALayer layoutSublayers] + 148
      frame #15: 0x04375244 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
      frame #16: 0x043750b0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
      frame #17: 0x042db7fa QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
      frame #18: 0x042dcb85 QuartzCore`CA::Transaction::commit() + 393
      frame #19: 0x0439a5b0 QuartzCore`+[CATransaction flush] + 52
      frame #20: 0x004849bb UIKit`_UIApplicationHandleEventQueue + 13095
      frame #21: 0x015aa77f CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
      frame #22: 0x015aa10b CoreFoundation`__CFRunLoopDoSources0 + 235
      frame #23: 0x015c71ae CoreFoundation`__CFRunLoopRun + 910
      frame #24: 0x015c69d3 CoreFoundation`CFRunLoopRunSpecific + 467
      frame #25: 0x015c67eb CoreFoundation`CFRunLoopRunInMode + 123
      frame #26: 0x02b5c5ee GraphicsServices`GSEventRunModal + 192
      frame #27: 0x02b5c42b GraphicsServices`GSEventRun + 104
      frame #28: 0x00486f9b UIKit`UIApplicationMain + 1225
      frame #29: 0x000026bd Niknik`main(argc=1, argv=0xbfffee74) + 141 at main.m:9
  </code></pre>
  
  <p>Also, the problem seems to be that the data source is getting deallocated somehow, because when I turned on zombies, I got this: </p>
  
  <p>-[CustomCollectionViewDataSource collectionView:numberOfItemsInSection:]: message sent to deallocated instance 0xa0a8d10</p>
  
  <p>What am I doing wrong?</p>