我在遍历 SQLite 数据库中执行批量插入的循环时遇到了一个严格的基于内存的问题。
我很确定这是关于内存的,我无法指出导致问题的变量。我已尽我所能释放所有分配的内容。
到目前为止,通过仪器分析没有内存泄漏。代码片段如下:
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];
}
任何帮助是极大的赞赏。请携手..!
提前致谢。