Я разрабатываю одно приложение, в котором повторяющиеся транзакции вставляются в базу данных. В то время как я делаю анализ кучи, он показывает предупреждение о нехватке памяти при вставке data.its, вставляя приблизительно 1200 записей. Код для вставки приведен ниже.
-(void)generateReccuringEntry:(int)tranId withAllDate:(BOOL)isAll
{
NSMutableArray *arrDates = [[NSMutableArray alloc] init] ;
NSArray *arr = [[_dicSaveData valueForKey:@"tran_repeatd"] componentsSeparatedByString:@" "];
int day;
if ([self getDayWithDayMonth:[arr objectAtIndex:1]] == 0) {
day = [self getDay:[arr objectAtIndex:1]];
}
else{
day = 1;
}
NSDate *startDate = [_dicSaveData valueForKey:@"tran_date"];
NSString *strEndDate = [NSString stringWithFormat:@"%@",[_dicSaveData valueForKey:@"tran_enddate"]];
NSDate *endDate = nil;
strEndDate = [strEndDate stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
if (![strEndDate stringIsEmpty]) {
endDate = [_dicSaveData valueForKey:@"tran_enddate"];
}
else {
//if end date not selected
endDate = [[startDate dateByAddingYear:1]lastOfYearDate];
}
//get start recurring day
NSString *strDay = [[arr lastObject] stringByReplacingOccurrencesOfString:@"()" withString:@""];
//check start recuring day selected or not
if ([strDay hasPrefix:@"("] && [strDay hasSuffix:@")"])
{
startDate = [self getStartDay:[arr lastObject] withStartingDate:startDate];
if ([startDate compare:endDate]==NSOrderedDescending || [startDate compare:endDate]==NSOrderedSame)
{
SafeRelease(arrDates);
return;
}
if (isAll)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:@"insert into recuring values (NULL,%i,%@,%@,'%@',%@,'%@','','%@','%@',%i,1,'%@',0)",tranId,[_dicSaveData valueForKey:@"cat_id"],[_dicSaveData valueForKey:@"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:@"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:@"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:@"Error!"];
}
}
else{
NSDate *currentDate = [[NSDate date] getDateWithDeviceTimeZone];
if ([startDate compare:currentDate]== NSOrderedDescending)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:@"insert into recuring values (NULL,%i,%@,%@,'%@',%@,'%@','','%@','%@',%i,1,'%@',0)",tranId,[_dicSaveData valueForKey:@"cat_id"],[_dicSaveData valueForKey:@"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:@"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:@"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:@"Error!"];
}
}
}
}
int index = 2;
if (day == 1) {
index = 1;
}
do {
if ([[arr objectAtIndex:index] isEqualToString:@"Week"])
{
startDate = [startDate dateByAddingWeek:day];
}
else if([[arr objectAtIndex:index] isEqualToString:@"Month"])
{
startDate = [startDate dateByAddingMonth:day];
}
else
{
startDate = [startDate dateByAddingDays:day];
}
if (isAll)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:@"insert into recuring values (NULL,%i,%@,%@,'%@',%@,'%@','','%@','%@',%i,1,'%@',0)",tranId,[_dicSaveData valueForKey:@"cat_id"],[_dicSaveData valueForKey:@"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:@"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:@"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:@"Error!"];
}
}
//add recuring for only for future dates
else
{
NSDate *currentDate = [[NSDate date] getDateWithDeviceTimeZone];
if ([startDate compare:currentDate]== NSOrderedDescending)
{
NSError *error = nil;
NSString *strQuery = [NSString stringWithFormat:@"insert into recuring values (NULL,%i,%@,%@,'%@',%@,'%@','','%@','%@',%i,1,'%@',0)",tranId,[_dicSaveData valueForKey:@"cat_id"],[_dicSaveData valueForKey:@"subcat_id"],_txtDesc.text,_txtAmount.text,sDate,[_dicSaveData valueForKey:@"tran_repeatd"],eDate,_flagForever,[_dicSaveData valueForKey:@"categoryText"]];
strQuery = [strQuery stringByReplacingOccurrencesOfString:@"(null)" withString:@""];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if (error) {
[AppDelegate showAlert:[error description] withTitle:@"Error!"];
}
}
}
} while ([startDate compare:endDate]==NSOrderedAscending );
SafeRelease(arrDates);
}
can anyone tell that what is the problem with this code.so that its consuming so much memory?
Обновление: я преобразовал приложение в ARC, но оно все еще показывает предупреждение о памяти.