【发布时间】:2011-01-05 21:09:34
【问题描述】:
我确定这与内存有关,但我似乎无法弄清楚是什么变量导致了我的问题。
据我所知,我将释放我分配的所有内容。如果这个循环运行 365 次而不是 730 次(一年中的天数),它似乎可以正常工作。
这是失败的代码的 sn-p。当程序在设备上结束时,它永远不会脱离循环。
非常感谢任何帮助。谢谢!
NSMutableArray *dtArray = [[NSMutableArray alloc] init];
double frequencyInterval = [Frequency doubleValue];
int i;
NSString *newDateString = @"";
NSString *sqlString = [NSString stringWithFormat:@"insert into ToDoList (TaskId, DueDate, Completed, Notes, Status, CompletedDate, Frequency) values ('%i', \"%@\", '0',\"%@\",'' ,'0', %@);", (int)self.AddTaskId, origDueDateString, NotesField, todoFrequency];
NSDate *nDate = dueDate;
NSDateFormatter *f3 = [[NSDateFormatter alloc] init];
[f3 setDateFormat:@"yyyy-MM-dd"];
for(i=0; i< 1000; i++) {
newDate = [newDate addTimeInterval:(frequencyInterval*86400)];
newDateString = [f3 stringFromDate:newDate];
if ([endRecurDate compare:newDate] == NSOrderedDescending)
{
[dtArray addObject:newDate];
if (i == 0)
{
sql = [sqlString stringByAppendingString:[NSString stringWithFormat:@"insert into ToDoList (TaskId, DueDate, Completed, Notes, Status, CompletedDate, Frequency) values ('%i', \"%@\", '0',\"%@\",'' ,'0', %@)", (int)self.AddTaskId, newDateString, NotesField, todoFrequency]];
}
else
{
sql = [sql stringByAppendingString:[NSString stringWithFormat:@";insert into ToDoList (TaskId, DueDate, Completed, Notes, Status, CompletedDate, Frequency) values ('%i', \"%@\", '0',\"%@\",'' ,'0', %@)", (int)self.AddTaskId, newDateString, NotesField, todoFrequency]];
}
//stringByAppendingString
}
else
{
break;
}
}
[dtArray release];
[f3 release];
【问题讨论】:
标签: iphone cocoa-touch xcode memory-management