title: NSDate basic usage error
body: <p>Next to a label showing the value of a slider i want to show the date that corresponds to a start date + the number of days in slider value units.</p>
  
  <p>When i move the slider the app crashes in the Simulator. As far as i could find out that happens when i try to create a new NSDate field and my startDate object being "out of scope".</p>
  
  <p>Reading a lot regarding retaining and releasing NSDate documentation had not helped me until now, because the documentation is so abstract that it seems to me that I'm not able to find the relevant part(s) in the documentation. I hope to understand more by example.</p>
  
  <p>So what's wrong with the following code (and from where in the documentation should a beginner have learned that) ?</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface SliderDateViewController : UIViewController {
      UILabel *dateLabel;
      UILabel *sliderValueLabel;
      UISlider *slider;
      NSDate *startDate;
  
  }
  
  @property (nonatomic, retain) IBOutlet UILabel *dateLabel;
  @property (nonatomic, retain) IBOutlet UILabel *sliderValueLabel;
  @property (nonatomic, retain) IBOutlet UISlider *slider;
  @property (nonatomic, retain) NSDate *startDate;
  
  -(IBAction)sliderValueChanged:(UISlider *)theSlider;
  
  @end
  
  
  #import "SliderDateViewController.h"
  
  @implementation SliderDateViewController
  
  @synthesize dateLabel;
  @synthesize sliderValueLabel;
  @synthesize slider;
  @synthesize startDate;
  
  - (void)viewDidLoad {
  
      [super viewDidLoad];
  
      dateLabel.text = @"01.01.2010";
  
      sliderValueLabel.text = @"0";
  
      NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
      [inputFormatter setDateFormat:@"dd.MM.yyyy"];
  
      self.startDate = [inputFormatter dateFromString:dateLabel.text];
  
      NSLog(@"startDate: ", self.startDate.description);
  
      [inputFormatter release];
  
  }
  
  -(IBAction)sliderValueChanged:(UISlider *)theSlider {
  
      int sliderValueAsInt = (int)(theSlider.value + 0.5f);
      NSString *newText = [[NSString alloc] initWithFormat:@"%d", sliderValueAsInt];
      sliderValueLabel.text = newText;
      [newText release];
  
      // Next line following the comment crashed with
      // *** -[CFDate release]: message sent to deallocated instance 0x3b07d10
      NSDate *newDate = [startDate addTimeInterval:86400 * sliderValueAsInt];
  
      NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
      [outputFormatter setDateFormat:@"dd.MM.yyyy"];
  
      dateLabel.text = [outputFormatter stringFromDate:newDate];
      [outputFormatter release];
      // [newDate release] // &lt;- this was the error
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning];
  }
  
  - (void)viewDidUnload {
  }
  
  
  - (void)dealloc {
      [dateLabel release];
      [sliderValueLabel release];
      [slider release];
      [startDate release];
      [super dealloc];
  }
  
  @end
  </code></pre>