gpt4 book ai didi

objective-c - iPhone - 程序接收信号 : 0 - on device but not on simulator ( Memory MAnagement Issue)

转载 作者:行者123 更新时间:2023-11-29 11:09:47 25 4
gpt4 key购买 nike

我正在经历一个严格的基于内存的问题,同时迭代一个在 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];
}

非常感谢任何帮助。请携手...!

提前致谢。

最佳答案

很明显,我们使用的字符串在每个实例中都会发生变异,因此 nsmutablestring 是优化的解决方案。此外,在分析函数时:

[NSMutableString replaceOccurrencesOfString:@"'" withString:@"''"]
[NSMutableString appendString:]

在仪器中,与您以前使用过的仪器相比,它们留下的内存足迹更少。

关于objective-c - iPhone - 程序接收信号 : 0 - on device but not on simulator ( Memory MAnagement Issue),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12053764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com