iPhone - Program Received Signal : 0 - on device but not on simulator
I'm sure this is memory related but I can't seem to figure out what variable is causing me problems.
I'm releasing everything I allocate as far as I can tell. This loop seems to work fine if it runs 365 times but not 730 (its doing days in a year).
Here is the snippet of code that is failing.. it never gets out of the loop when the program ends on the device.
Any help is greatly appreciate. Thanks!
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];
For one thing, you don't need to inialize newDateString
to @""
; simply declaring it there is enough.
I didn't notice any obvious memory leaks, but you are looping through the for
statement 1,000 times. All of your autoreleased objects may not be released until the entire loop is done, so that may be why you're using too much memory. To release them during the loop, do this:
for(i=0; i< 1000; i++) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
/* your code here */
[pool drain];
}
Play with this a little bit; you probably don't need to drain the pool every single time your loop executes, but you might build a counter and drain the pool every 25 loops or so.
精彩评论