title: release view controller and removing view
body: <p>Quick question:</p>
  
  <p>If I use </p>
  
  <pre><code>[someViewController.view addSubView:otherViewController.view];
  </code></pre>
  
  <p>to add a view. And then use</p>
  
  <pre><code>[otherViewController.view removeFromSuperView] 
  </code></pre>
  
  <p>to remove the view, my app will crash when I call <code>[otherViewController release]</code></p>
  
  <p>The crash point is in the <code>[super dealloc]</code> line in my <code>dealloc</code> method of <code>otherViewControll</code> class implementation.</p>
  
  <p>otherViewController is a reference to the view controller. I call release after its view has been removeFromSuperView'ed. By the time I call release, it's a valid pointer. </p>
  
  <p>What am I doing wrong here?</p>
  
  <p>otherViewController's dealloc class implementation</p>
  
  <pre><code>- (void)dealloc {
      [popVC release];
      [photoContainer release];
      [photoView release];
      [recordName release];
      [recordIngr release];
      [recordDesc release];
      [recordPrice release];
      [quantity release];
      [pricingLabel release];
      [increaseButton release];
      [decreaseButton release];
  
      [pricingTableVC release];
      [pricingTable release];
  
      [super dealloc];   // &lt;--- crash point
  }
  </code></pre>
  
  <p>updated: call trace</p>
  
  <pre><code>2011-06-04 00:35:05.110 MyApp[2308:207] -[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0
  2011-06-04 00:35:05.124 MyApp[2308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0'
  *** Call stack at first throw:
  (
      0   CoreFoundation                      0x00dd75a9 __exceptionPreprocess + 185
      1   libobjc.A.dylib                     0x00f2b313 objc_exception_throw + 44
      2   CoreFoundation                      0x00dd90bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
      3   CoreFoundation                      0x00d48966 ___forwarding___ + 966
      4   CoreFoundation                      0x00d48522 _CF_forwarding_prep_0 + 50
      5   UIKit                               0x00379051 -[UIViewController dealloc] + 128
      6   MyApp                              0x00009b26 -[RecordDetailViewController dealloc] + 797
      7   MyApp                              0x00004744 __-[RecordRootViewController bringUpNextRecordDetail:isNext:]_block_invoke_2 + 77
      8   UIKit                               0x002f7fb9 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 294
      9   UIKit                               0x002f7e4b -[UIViewAnimationState animationDidStop:finished:] + 77
      10  QuartzCore                          0x01d7b99b _ZL23run_animation_callbacksdPv + 278
      11  QuartzCore                          0x01d20651 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
      12  CoreFoundation                      0x00db88c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
      13  CoreFoundation                      0x00db9e74 __CFRunLoopDoTimer + 1220
      14  CoreFoundation                      0x00d162c9 __CFRunLoopRun + 1817
      15  CoreFoundation                      0x00d15840 CFRunLoopRunSpecific + 208
      16  CoreFoundation                      0x00d15761 CFRunLoopRunInMode + 97
      17  GraphicsServices                    0x0172e1c4 GSEventRunModal + 217
      18  GraphicsServices                    0x0172e289 GSEventRun + 115
      19  UIKit                               0x002d5c93 UIApplicationMain + 1160
      20  MyApp                              0x0000200c main + 102
      21  MyApp                              0x00001f9d start + 53
  )
  terminate called after throwing an instance of 'NSException'
  </code></pre>
  
  <p><strong>Update</strong>: 
  in -viewDidLoad, I have a gesture recognizer:</p>
  
  <pre><code>{
      UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showNextRecod:)];
      [leftSwipeGestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
      [self.view addGestureRecognizer:leftSwipeGestureRecognizer];
      [leftSwipeGestureRecognizer release];
  
  }
  </code></pre>
  
  <p>I tried to use a Button to call -(IBAction) showNextRecod, <strong>it won't crash!!</strong> Only when I use the gesture to call the same method, it would crash</p>
  
  <p>Regards</p>
  
  <p>Leo</p>