gpt4 book ai didi

ios - 方法泄漏中的对象

转载 作者:行者123 更新时间:2023-11-28 23:04:41 25 4
gpt4 key购买 nike

还有另一个泄漏问题。我有一个方法:

-(NSMutableArray*)returnItems:(int)nominalID subCountryID:(int)subCountryID
{
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path =
[documentsDirectory stringByAppendingPathComponent:databaseName];

NSMutableArray *itemsArray=[[[NSMutableArray alloc]init]autorelease];

if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
const char *sqlItems=sqlite3_mprintf("SELECT itm.itemID,itm.itemYear,itm.rarity,itm.mintage,iaval.availability as avalibility,iaval.quality as quality,itm.Mintmark,itm.specialRemark,iaval.dated\
from items as itm\
inner join itemAvailability as iaval on itm.itemID=iaval.itemID\
INNER join NominalsAndSubcountriesRelation as nasr on nasr.nominalID=itm.relatedToNominal\
WHERE nasr.nominalID=%i AND nasr.subCountryID=%i",nominalID,subCountryID);

sqlite3_stmt *statement;
int sqlResult = sqlite3_prepare_v2(database, sqlItems, -1, &statement, NULL);
if ( sqlResult== SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
Item *item=[[Item alloc]init];
item.itemID=sqlite3_column_int(statement, 0);
char *itemYear=(char *)sqlite3_column_text(statement, 1);
item.rarity=sqlite3_column_int(statement, 2);
char *mintage=(char *)sqlite3_column_text(statement, 3);
item.availability=sqlite3_column_int(statement, 4);
item.quality=sqlite3_column_int(statement, 5);
char *mintmark=(char *)sqlite3_column_text(statement, 6);
char *specialRemark=(char*)sqlite3_column_text(statement, 7);
char *dated=(char*)sqlite3_column_text(statement, 8);
item.itemYear=(itemYear)?[NSString stringWithUTF8String:itemYear]:@"";
item.mintage=(mintage)?[NSString stringWithUTF8String:mintage]:@"Unknown";
item.mintmark=(mintmark)?[NSString stringWithUTF8String:mintmark]:@"";
item.specialRemark=(specialRemark)?[NSString stringWithUTF8String:specialRemark]:@"";
item.dated=(dated)?[NSString stringWithUTF8String:dated]:@"";
[itemsArray addObject:item];
[item release];
}
sqlite3_finalize(statement);
sqlite3_free((char*)sqlItems);
}
}
else
{
[self dbConnectionError];
}

return itemsArray;
}

instruments 工具声称项目对象有 100% 泄漏。有什么问题吗?

最佳答案

您提供的代码似乎没有任何错误; item 在添加到 itemsArray 后被释放并且 itemsArray 被自动释放,因此作为非拥有引用返回。

因此,您应该假设接收 itemsArray 的人正在保留它并且未能释放它。

关于ios - 方法泄漏中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9509719/

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