我们得到一个SIGBUS(BUS_ADRALN),它指向这个线程。导致此错误的原因是什么?第68行是NSString * dateString = [dateFormat stringFromDate:currentTimestamp];或[dateFormat release];
NSDate *currentTimestamp = self.timestamp;
if (!currentTimestamp)
return nil; // sanity check
[currentTimestamp retain];
NSDateComponents *otherDay = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentTimestamp];
NSDateComponents *today = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[NSDate date]];
NSDateComponents *yesterday = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[[NSDate date] addTimeInterval: -24 * 60 * 60]];
if ([today day] == [otherDay day] &&
[today month] == [otherDay month] &&
[today year] == [otherDay year]) {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"h:mm a"];
NSString *dateString = [dateFormat stringFromDate:currentTimestamp];
[dateFormat release];
[currentTimestamp release];
return [NSString stringWithFormat:@"Today %@", dateString];
}
else if ([yesterday day] == [otherDay day] &&
[yesterday month] == [otherDay month] &&
[yesterday year] == [otherDay year]) {
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"h:mm a"];
NSString *dateString = [dateFormat stringFromDate:currentTimestamp];
[dateFormat release];
[currentTimestamp release];
return [NSString stringWithFormat:@"Yesterday %@", dateString];
}
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy h:mm a"];
// below is line 68
NSString *dateString = [dateFormat stringFromDate:currentTimestamp];
[dateFormat release];
[currentTimestamp release];
return dateString;
0 CoreFoundation 0x33474894 CFDateFormatterCreateStringWithAbsoluteTime + 60
1 CoreFoundation 0x33474817 CFDateFormatterCreateStringWithDate + 31
2 Foundation 0x326c4ad7 -[NSDateFormatter stringForObjectValue:] + 91
3 Foundation 0x326c4a75 -[NSDateFormatter stringFromDate:] + 21
4 MyApp 0x000a81dc -[Message getFormattedTimestamp] (Message.m:68)
5 MyApp 0x0007b7a4 -[ConversationView newBubble:withFrame:] (ConversationView.m:452)
6 MyApp 0x0007b2fc -[ConversationView tableView:heightForRowAtIndexPath:] (ConversationView.m:520)
7 UIKit 0x31bb3b09 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2173
8 UIKit 0x31bb3225 -[UITableViewRowData numberOfRows] + 73
9 UIKit 0x31bb2c73 -[UITableView noteNumberOfRowsChanged] + 83
10 UIKit 0x31bb27f7 -[UITableView reloadData] + 583
11 MyApp 0x0007cccc -[ConversationView reloadAndMoveToEnd:] (ConversationView.m:147)
12 MyApp 0x0007cc6c -[ConversationView managedObjectContext:fetchCompletedForRequest:withResults:error:] (ConversationView.m:153)
13 MyApp 0x00197670 -[IZManagedObjectContext backgroundFetchOperation:completedWithIDs:error:] (IZManagedObjectContext.m:150)
14 MyApp 0x001970b0 -[IZBackgroundFetchOperation fetchRequestDidCompleteWithUserInfo:] (IZBackgroundFetchOperation.m:108)
15 CoreFoundation 0x3347df03 -[NSObject(NSObject) performSelector:withObject:] + 23
16 Foundation 0x327237a9 __NSThreadPerformPerform + 269
17 CoreFoundation 0x334e7a79 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 13
18 CoreFoundation 0x334e975f __CFRunLoopDoSources0 + 383
19 CoreFoundation 0x334ea4eb __CFRunLoopRun + 231
20 CoreFoundation 0x3347aec3 CFRunLoopRunSpecific + 231
21 CoreFoundation 0x3347adcb CFRunLoopRunInMode + 59
22 GraphicsServices 0x311a541f GSEventRunModal + 115
23 GraphicsServices 0x311a54cb GSEventRun + 63
24 UIKit 0x31b90d69 -[UIApplication _run] + 405
25 UIKit 0x31b8e807 UIApplicationMain + 671
26 MyApp 0x0009b578 main (main.m:5)
答案 0 :(得分:0)
好吧,上面的代码很好,因为我们最终为它编写了一个单元测试。事实证明这是一个记忆问题。奇怪的是它始终指向这条线。