I'm going through a rigorous memory based issue while iterating over a loop performing bulk insertion in SQLite database .
I'm quiet sure this is memory concerned and I'm unable to point out the variable causing problems. I have released everything allocated as far as I can check.
There are no memory leaks upto this point analyzed through instruments. The snippet of code is as follows :
int m=0;
while ([arrData count]!=0) {
if (newQuery) {
exeQuery = query;
newQuery = false;
}
else
{
exeQuery=[exeQuery stringByAppendingFormat:@" UNION"];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithDictionary:[arrData objectAtIndex:0]];
[data removeObjectForKey:@"statement"];
[data removeObjectForKey:@"datetime_stamp"];
NSString *strVal=@"";
NSString *_value=@"";
int i=0;
for(;i<[keys count]-1;i++)
{
if(_value==nil || _value==NULL){
_value=@"";
}
_value=[NSString stringWithFormat:@"%@",[data objectForKey:[keys objectAtIndex:i]]];
_value=[_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
strVal=[strVal stringByAppendingFormat:@"'%@',",_value];
}
if(_value==nil || _value==NULL){
_value=@"";
}
_value=[NSString stringWithFormat:@"%@",[data objectForKey:[keys objectAtIndex:i]]];
_value=[_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
strVal=[strVal stringByAppendingFormat:@"'%@'",_value];
exeQuery=[exeQuery stringByAppendingFormat:@" SELECT %@",strVal];
if (m!=0 && m%499==0) {
[DataSource executeQuery:exeQuery];
//db.execute(exeQuery);
newQuery = true;
}
[data release];
[arrData removeObjectAtIndex:0];
m++;
}
for (;m<locations_length; m++) {
if (newQuery) {
exeQuery = query;
newQuery = false;
}
else
{
exeQuery=[exeQuery stringByAppendingFormat:@" UNION"];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithDictionary:[arrData objectAtIndex:m]];
[data removeObjectForKey:@"statement"];
[data removeObjectForKey:@"datetime_stamp"];
NSString *strVal=@"";
NSString *_value=@"";
int i=0;
for(;i<[keys count]-1;i++)
{
if(_value==nil || _value==NULL){
_value=@"";
}
_value=[NSString stringWithFormat:@"%@",[data objectForKey:[keys objectAtIndex:i]]];
_value=[_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
strVal=[strVal stringByAppendingFormat:@"'%@',",_value];
}
if(_value==nil || _value==NULL){
_value=@"";
}
_value=[NSString stringWithFormat:@"%@",[data objectForKey:[keys objectAtIndex:i]]];
_value=[_value stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
strVal=[strVal stringByAppendingFormat:@"'%@'",_value];
exeQuery=[exeQuery stringByAppendingFormat:@" SELECT %@",strVal];
if (m!=0 && m%499==0) {
[DataSource executeQuery:exeQuery];
//db.execute(exeQuery);
newQuery = true;
}
[data release];
}
Any help is greatly appreciated. Plz join hands.. !
Thanks in advance.