-[__NSDate timeIntervalSinceReferenceDate]: message sent to deallocated
<p>I am working on an iphone app, in which to count the number of days between two dates I am using the code as follows:</p>

<pre><code>    double intevalInSeconds = [selectedDate2 timeIntervalSinceDate:newfromdate];
int dayInSeconds = 60 * 60 * 24;
int day = intevalInSeconds / dayInSeconds;
NSLog(@"counted days are:%d",day);
NSDateFormatter *df=[[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:     
    NSGregorianCalendar];
NSDateComponents *days = [[NSDateComponents alloc] init];
NSInteger dayCount = 0;
while ( TRUE ) {
    [days setDay: ++dayCount];
    NSDate *date = [gregorianCalendar dateByAddingComponents: days toDate: newfromdate 
            options: 0];
    if ( [date compare: selectedDate2] == NSOrderedDescending )
        break;
    NSString *dateForAdd=[df stringFromDate:date];
    [countdays addObject:dateForAdd];
}
NSLog(@"daysdetail:%@",countdays);
appendarray = countdays;
NSLog(@"append array is:%@",appendarray);
}
</code></pre>

<p>When i run this app on simulator it is working fine but whenever I tried to run it on device it is giving the error|:- [__NSDate timeIntervalSinceReferenceDate]: message sent to deallocated instance 0x65a30b0</p>

<p>Please tell me if I doing some wrong in the above code.</p>

<p>Thanks alot.</p>
